@remoteoss/json-schema-form 0.4.3-beta.0 → 0.4.4-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,9 @@
1
+ #### 0.4.4-beta.0 (2023-08-30)
2
+
3
+ ##### Chores
4
+
5
+ * **fieldset:** ignore values not matching the field type ([#44](https://github.com/remoteoss/json-schema-form/pull/44)) ([f0af54e5](https://github.com/remoteoss/json-schema-form/commit/f0af54e5d425fb78524ab150bb31629d00369a61))
6
+
1
7
  #### 0.4.3-beta.0 (2023-08-09)
2
8
 
3
9
  ##### Bug fixes
package/dist/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2023 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.4.3-beta.0
5
- Generated: Wed, 09 Aug 2023 08:39:30 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.4.4-beta.0
5
+ Generated: Wed, 30 Aug 2023 17:33:30 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -749,7 +749,16 @@ function getPrefillSubFieldValues(field, defaultValues, parentFieldKeyPath) {
749
749
  initialValue[field.name] = subFieldValues;
750
750
  }
751
751
  } else {
752
- initialValue = getPrefillValues([field], initialValue);
752
+ if (typeof initialValue !== "object") {
753
+ console.warn(
754
+ `Field "${parentFieldKeyPath}"'s value is "${initialValue}", but should be type object.`
755
+ );
756
+ initialValue = getPrefillValues([field], {
757
+ // TODO nested fieldsets are not handled
758
+ });
759
+ } else {
760
+ initialValue = getPrefillValues([field], initialValue);
761
+ }
753
762
  }
754
763
  return initialValue;
755
764
  }
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2023 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.4.3-beta.0
5
- Generated: Wed, 09 Aug 2023 08:39:30 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.4.4-beta.0
5
+ Generated: Wed, 30 Aug 2023 17:33:30 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -713,7 +713,16 @@ function getPrefillSubFieldValues(field, defaultValues, parentFieldKeyPath) {
713
713
  initialValue[field.name] = subFieldValues;
714
714
  }
715
715
  } else {
716
- initialValue = getPrefillValues([field], initialValue);
716
+ if (typeof initialValue !== "object") {
717
+ console.warn(
718
+ `Field "${parentFieldKeyPath}"'s value is "${initialValue}", but should be type object.`
719
+ );
720
+ initialValue = getPrefillValues([field], {
721
+ // TODO nested fieldsets are not handled
722
+ });
723
+ } else {
724
+ initialValue = getPrefillValues([field], initialValue);
725
+ }
717
726
  }
718
727
  return initialValue;
719
728
  }
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2023 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.4.3-beta.0
5
- Generated: Wed, 09 Aug 2023 08:39:30 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.4.4-beta.0
5
+ Generated: Wed, 30 Aug 2023 17:33:30 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -11689,7 +11689,16 @@ function getPrefillSubFieldValues(field, defaultValues, parentFieldKeyPath) {
11689
11689
  initialValue[field.name] = subFieldValues;
11690
11690
  }
11691
11691
  } else {
11692
- initialValue = getPrefillValues([field], initialValue);
11692
+ if (typeof initialValue !== "object") {
11693
+ console.warn(
11694
+ `Field "${parentFieldKeyPath}"'s value is "${initialValue}", but should be type object.`
11695
+ );
11696
+ initialValue = getPrefillValues([field], {
11697
+ // TODO nested fieldsets are not handled
11698
+ });
11699
+ } else {
11700
+ initialValue = getPrefillValues([field], initialValue);
11701
+ }
11693
11702
  }
11694
11703
  return initialValue;
11695
11704
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remoteoss/json-schema-form",
3
- "version": "0.4.3-beta.0",
3
+ "version": "0.4.4-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",
@@ -18,6 +18,7 @@ import {
18
18
  schemaInputTypeSelectMultipleDeprecated,
19
19
  schemaInputTypeSelectMultiple,
20
20
  schemaInputTypeSelectMultipleOptional,
21
+ schemaInputTypeFieldset,
21
22
  schemaInputTypeNumber,
22
23
  schemaInputTypeNumberZeroMaximum,
23
24
  schemaInputTypeDate,
@@ -92,12 +93,15 @@ const getField = (fields, name, ...subNames) => {
92
93
  };
93
94
 
94
95
  beforeEach(() => {
96
+ jest.spyOn(console, 'warn').mockImplementation(() => {});
95
97
  jest.spyOn(console, 'error').mockImplementation(() => {});
96
98
  });
97
99
 
98
100
  afterEach(() => {
99
101
  expect(console.error).not.toHaveBeenCalled();
100
102
  console.error.mockRestore();
103
+ expect(console.warn).not.toHaveBeenCalled();
104
+ console.warn.mockRestore();
101
105
  });
102
106
 
103
107
  describe('createHeadlessForm', () => {
@@ -3446,6 +3450,27 @@ describe('createHeadlessForm', () => {
3446
3450
  ],
3447
3451
  });
3448
3452
  });
3453
+
3454
+ it('should ignore initial values that do not match the field type (eg string vs object)', () => {
3455
+ const result = createHeadlessForm(schemaInputTypeFieldset, {
3456
+ initialValues: {
3457
+ a_fieldset: 'foo', // should be an object instead of string
3458
+ },
3459
+ });
3460
+
3461
+ // It returns fields without errors
3462
+ expect(result.fields).toBeDefined();
3463
+ expect(result.fields[0].fields[0].name).toBe('id_number');
3464
+ expect(result.fields[0].fields[1].name).toBe('tabs');
3465
+
3466
+ // Warn about those missmatched values
3467
+ expect(console.warn).toHaveBeenCalledWith(
3468
+ `Field "a_fieldset"'s value is "foo", but should be type object.`
3469
+ );
3470
+ console.warn.mockClear();
3471
+
3472
+ expect(console.error).not.toHaveBeenCalled();
3473
+ });
3449
3474
  });
3450
3475
  });
3451
3476
 
@@ -1020,12 +1020,12 @@ export const schemaInputTypeFileWithSkippable = JSONSchemaBuilder()
1020
1020
  })
1021
1021
  .build();
1022
1022
 
1023
- export const schemaInputTypeFieldset = JSONSchemaBuilder()
1024
- .addInput({
1023
+ export const schemaInputTypeFieldset = {
1024
+ properties: {
1025
1025
  a_fieldset: mockFieldset,
1026
- })
1027
- .setRequiredFields(['a_fieldset'])
1028
- .build();
1026
+ },
1027
+ required: ['a_fieldset'],
1028
+ };
1029
1029
 
1030
1030
  export const schemaInputTypeFocusedFieldset = JSONSchemaBuilder()
1031
1031
  .addInput({