@remoteoss/json-schema-form 0.7.7-dev.20240129180839 → 0.8.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ #### 0.8.1-beta.0 (2024-02-12)
2
+
3
+ ##### Bug Fixes
4
+
5
+ * **conditionals:** Certain conditions in a JSON schema were failing. This bugfix adds missing field context to the evaluation to prevent the error. ([#65](https://github.com/remoteoss/json-schema-form/pull/65)) ([6755a2fd](https://github.com/remoteoss/json-schema-form/commit/6755a2fd29f3f806a57ba19e29ad7e21daf9e51b))
6
+
7
+ #### 0.8.0-beta.0 (2024-02-01)
8
+
9
+ ##### Bug Fixes
10
+
11
+ * **fieldset:** Support customProperties with sub-fields clashing with reserved words. ([#64](https://github.com/remoteoss/json-schema-form/pull/64)) ([8340cdea](https://github.com/remoteoss/json-schema-form/commit/8340cdea27b711064079055af939a595d1c38031))
12
+
1
13
  #### 0.7.6-beta.0 (2024-01-23)
2
14
 
3
15
  ##### Chores
package/dist/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2024 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.7.7-dev.20240129180839
5
- Generated: Mon, 29 Jan 2024 18:09:02 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.8.1-beta.0
5
+ Generated: Mon, 12 Feb 2024 12:22:48 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -130,10 +130,8 @@ function checkIfConditionMatchesProperties(node, formValues, formFields, logic)
130
130
  const field = getField(name, formFields);
131
131
  return validateFieldSchema(
132
132
  {
133
- options: field.options,
134
- // @TODO/CODE SMELL. We are passing the property (raw field), but buildYupSchema() expected the output field.
133
+ ...field,
135
134
  ...currentProperty,
136
- inputType: field.inputType,
137
135
  required: true
138
136
  },
139
137
  value
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2024 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.7.7-dev.20240129180839
5
- Generated: Mon, 29 Jan 2024 18:09:02 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.8.1-beta.0
5
+ Generated: Mon, 12 Feb 2024 12:22:48 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -94,10 +94,8 @@ function checkIfConditionMatchesProperties(node, formValues, formFields, logic)
94
94
  const field = getField(name, formFields);
95
95
  return validateFieldSchema(
96
96
  {
97
- options: field.options,
98
- // @TODO/CODE SMELL. We are passing the property (raw field), but buildYupSchema() expected the output field.
97
+ ...field,
99
98
  ...currentProperty,
100
- inputType: field.inputType,
101
99
  required: true
102
100
  },
103
101
  value
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2024 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.7.7-dev.20240129180839
5
- Generated: Mon, 29 Jan 2024 18:09:02 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.8.1-beta.0
5
+ Generated: Mon, 12 Feb 2024 12:22:48 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -11449,10 +11449,8 @@ function checkIfConditionMatchesProperties(node, formValues, formFields, logic)
11449
11449
  const field = getField(name, formFields);
11450
11450
  return validateFieldSchema(
11451
11451
  {
11452
- options: field.options,
11453
- // @TODO/CODE SMELL. We are passing the property (raw field), but buildYupSchema() expected the output field.
11452
+ ...field,
11454
11453
  ...currentProperty,
11455
- inputType: field.inputType,
11456
11454
  required: true
11457
11455
  },
11458
11456
  value
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remoteoss/json-schema-form",
3
- "version": "0.7.7-dev.20240129180839",
3
+ "version": "0.8.1-beta.0",
4
4
  "description": "Headless UI form powered by JSON Schemas",
5
5
  "author": "Remote.com <engineering@remote.com> (https://remote.com/)",
6
6
  "license": "MIT",
@@ -423,3 +423,59 @@ describe('Conditional attributes updated', () => {
423
423
  expect(fields[1].visibilityCondition).toEqual(expect.any(Function));
424
424
  });
425
425
  });
426
+
427
+ describe('Conditional with a minimum value check', () => {
428
+ it('Should handle a maximum as a property field check', () => {
429
+ const schema = {
430
+ additionalProperties: false,
431
+ allOf: [
432
+ {
433
+ if: {
434
+ properties: {
435
+ salary: {
436
+ maximum: 119999,
437
+ },
438
+ },
439
+ required: ['salary'],
440
+ },
441
+ then: {
442
+ required: ['reason'],
443
+ },
444
+ else: {
445
+ properties: {
446
+ reason: false,
447
+ },
448
+ },
449
+ },
450
+ ],
451
+ properties: {
452
+ salary: {
453
+ type: 'number',
454
+ 'x-jsf-presentation': {
455
+ inputType: 'money',
456
+ },
457
+ },
458
+ reason: {
459
+ oneOf: [
460
+ {
461
+ const: 'reason_one',
462
+ },
463
+ {
464
+ const: 'reason_two',
465
+ },
466
+ ],
467
+ type: 'string',
468
+ },
469
+ },
470
+ required: ['salary'],
471
+ type: 'object',
472
+ };
473
+
474
+ const { handleValidation } = createHeadlessForm(schema, { strictInputType: false });
475
+ expect(handleValidation({ salary: 120000 }).formErrors).toEqual(undefined);
476
+ expect(handleValidation({ salary: 1000 }).formErrors).toEqual({
477
+ reason: 'Required field',
478
+ });
479
+ expect(handleValidation({ salary: 1000, reason: 'reason_one' }).formErrors).toEqual(undefined);
480
+ });
481
+ });
@@ -357,23 +357,21 @@ describe('createHeadlessForm() - custom validations', () => {
357
357
  minimum: 24,
358
358
  maximum: 28,
359
359
  },
360
- second_gen: {
360
+ second_gen: {
361
361
  customProperties: {
362
362
  cub_age: {
363
- minimum: 18,
364
- maximum: 21
365
- },
366
- third_gen: {
367
- customProperties: {
368
- grandcub_age: {
369
- minimum: 10,
370
- maximum: 15,
363
+ minimum: 18,
364
+ maximum: 21,
365
+ },
366
+ third_gen: {
367
+ customProperties: {
368
+ grandcub_age: {
369
+ minimum: 10,
370
+ maximum: 15,
371
+ },
371
372
  },
372
- }
373
-
374
- },
373
+ },
375
374
  },
376
-
377
375
  },
378
376
  },
379
377
  },
@@ -3760,6 +3760,58 @@ describe('createHeadlessForm', () => {
3760
3760
  expect(nestedFieldsetResult.fields[0].fields[1]).not.toHaveProperty('data-field');
3761
3761
  expect(nestedFieldsetResult.fields[0].fields[1]).not.toHaveProperty('data-fieldset');
3762
3762
  });
3763
+ it('should handle custom properties when inside fieldsets for fields name clashing with reserved words', () => {
3764
+ const { fields } = createHeadlessForm(
3765
+ {
3766
+ properties: {
3767
+ dog: {
3768
+ title: 'Dog details',
3769
+ description: 'Fieldset description',
3770
+ 'x-jsf-presentation': {
3771
+ inputType: 'fieldset',
3772
+ },
3773
+ properties: {
3774
+ name: {
3775
+ // This fieldName (name) clashs with the field specs "name"
3776
+ title: 'Dogs name',
3777
+ 'x-jsf-presentation': {
3778
+ inputType: 'text',
3779
+ },
3780
+ type: 'string',
3781
+ },
3782
+ type: {
3783
+ // This field name (type) clashs with the field specs "type"
3784
+ title: 'Breed type',
3785
+ 'x-jsf-presentation': {
3786
+ inputType: 'number',
3787
+ },
3788
+ type: 'string',
3789
+ },
3790
+ },
3791
+ required: ['name'],
3792
+ type: 'object',
3793
+ },
3794
+ },
3795
+ required: ['dog'],
3796
+ },
3797
+ {
3798
+ customProperties: {
3799
+ dog: {
3800
+ customProperties: {
3801
+ name: {
3802
+ description: "What's your dogs name",
3803
+ },
3804
+ },
3805
+ },
3806
+ },
3807
+ }
3808
+ );
3809
+
3810
+ expect(fields.length).toBe(1);
3811
+ expect(fields[0].fields.length).toBe(2);
3812
+ expect(fields[0].fields[0].name).toBe('name');
3813
+ expect(fields[0].fields[0].description).toBe("What's your dogs name");
3814
+ });
3763
3815
  });
3764
3816
 
3765
3817
  describe('presentation (deprecated in favor of x-jsf-presentation)', () => {