@remoteoss/json-schema-form 0.11.6-beta.0 → 0.11.7-dev.20241025154552

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/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.11.6-beta.0
5
- Generated: Tue, 15 Oct 2024 12:38:54 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.7-dev.20241025154552
5
+ Generated: Fri, 25 Oct 2024 15:46:26 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -470,7 +470,7 @@ var validateRadioOrSelectOptions = (value, options) => {
470
470
  var yupSchemas = {
471
471
  text: validateOnlyStrings,
472
472
  radioOrSelectString: (options) => {
473
- return (0, import_yup.string)().nullable().transform((value) => {
473
+ return (0, import_yup.mixed)().nullable().transform((value) => {
474
474
  if (value === "") {
475
475
  return void 0;
476
476
  }
@@ -481,7 +481,12 @@ var yupSchemas = {
481
481
  }).test(
482
482
  "matchesOptionOrPattern",
483
483
  ({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
484
- (value) => validateRadioOrSelectOptions(value, options)
484
+ (value) => {
485
+ if (value !== void 0 && typeof value !== "string") {
486
+ return false;
487
+ }
488
+ return validateRadioOrSelectOptions(value, options);
489
+ }
485
490
  );
486
491
  },
487
492
  date: ({ minDate, maxDate }) => {
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.11.6-beta.0
5
- Generated: Tue, 15 Oct 2024 12:38:54 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.7-dev.20241025154552
5
+ Generated: Fri, 25 Oct 2024 15:46:26 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -433,7 +433,7 @@ var validateRadioOrSelectOptions = (value, options) => {
433
433
  var yupSchemas = {
434
434
  text: validateOnlyStrings,
435
435
  radioOrSelectString: (options) => {
436
- return string().nullable().transform((value) => {
436
+ return mixed().nullable().transform((value) => {
437
437
  if (value === "") {
438
438
  return void 0;
439
439
  }
@@ -444,7 +444,12 @@ var yupSchemas = {
444
444
  }).test(
445
445
  "matchesOptionOrPattern",
446
446
  ({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
447
- (value) => validateRadioOrSelectOptions(value, options)
447
+ (value) => {
448
+ if (value !== void 0 && typeof value !== "string") {
449
+ return false;
450
+ }
451
+ return validateRadioOrSelectOptions(value, options);
452
+ }
448
453
  );
449
454
  },
450
455
  date: ({ minDate, maxDate }) => {
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2024 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.11.6-beta.0
5
- Generated: Tue, 15 Oct 2024 12:38:54 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.7-dev.20241025154552
5
+ Generated: Fri, 25 Oct 2024 15:46:26 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -11949,7 +11949,7 @@ var validateRadioOrSelectOptions = (value, options) => {
11949
11949
  var yupSchemas = {
11950
11950
  text: validateOnlyStrings,
11951
11951
  radioOrSelectString: (options) => {
11952
- return StringSchema().nullable().transform((value) => {
11952
+ return SchemaType().nullable().transform((value) => {
11953
11953
  if (value === "") {
11954
11954
  return void 0;
11955
11955
  }
@@ -11960,7 +11960,12 @@ var yupSchemas = {
11960
11960
  }).test(
11961
11961
  "matchesOptionOrPattern",
11962
11962
  ({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
11963
- (value) => validateRadioOrSelectOptions(value, options)
11963
+ (value) => {
11964
+ if (value !== void 0 && typeof value !== "string") {
11965
+ return false;
11966
+ }
11967
+ return validateRadioOrSelectOptions(value, options);
11968
+ }
11964
11969
  );
11965
11970
  },
11966
11971
  date: ({ minDate, maxDate }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remoteoss/json-schema-form",
3
- "version": "0.11.6-beta.0",
3
+ "version": "0.11.7-dev.20241025154552",
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",
@@ -9,6 +9,7 @@ import {
9
9
  schemaInputTypeText,
10
10
  schemaInputTypeRadioDeprecated,
11
11
  schemaInputTypeRadioString,
12
+ schemaInputTypeRadioStringY,
12
13
  schemaInputTypeRadioBoolean,
13
14
  schemaInputTypeRadioNumber,
14
15
  schemaInputTypeRadioRequiredAndOptional,
@@ -820,6 +821,45 @@ describe('createHeadlessForm', () => {
820
821
  });
821
822
  });
822
823
 
824
+ // @BUG COD-1859
825
+ // it should validate when type is string but value is not a boolean
826
+ it('support "radio" field string-y type', () => {
827
+ const { fields, handleValidation } = createHeadlessForm(schemaInputTypeRadioStringY);
828
+
829
+ const validateForm = (vals) => friendlyError(handleValidation(vals));
830
+
831
+ expect(fields).toMatchObject([
832
+ {
833
+ description: 'Do you have any siblings?',
834
+ label: 'Has siblings',
835
+ name: 'has_siblings',
836
+ options: [
837
+ {
838
+ label: 'Yes',
839
+ value: 'true',
840
+ },
841
+ {
842
+ label: 'No',
843
+ value: 'false',
844
+ },
845
+ ],
846
+ required: true,
847
+ schema: expect.any(Object),
848
+ type: 'radio',
849
+ },
850
+ ]);
851
+
852
+ assertOptionsAllowed({
853
+ handleValidation,
854
+ fieldName: 'has_siblings',
855
+ validOptions: ['true', 'false'],
856
+ });
857
+
858
+ expect(validateForm({ has_siblings: false })).toEqual({
859
+ has_siblings: 'The option false is not valid.',
860
+ });
861
+ });
862
+
823
863
  it('support "radio" field number type', () => {
824
864
  const { fields, handleValidation } = createHeadlessForm(schemaInputTypeRadioNumber);
825
865
 
@@ -148,6 +148,25 @@ export const mockRadioInputBoolean = {
148
148
  type: 'boolean',
149
149
  };
150
150
 
151
+ export const mockRadioInputStringY = {
152
+ title: 'Has siblings',
153
+ description: 'Do you have any siblings?',
154
+ oneOf: [
155
+ {
156
+ title: 'Yes',
157
+ const: 'true',
158
+ },
159
+ {
160
+ title: 'No',
161
+ const: 'false',
162
+ },
163
+ ],
164
+ 'x-jsf-presentation': {
165
+ inputType: 'radio',
166
+ },
167
+ type: 'string',
168
+ };
169
+
151
170
  export const mockRadioInputNumber = {
152
171
  title: 'Number of siblings',
153
172
  description: 'How many siblings do you have?',
@@ -899,6 +918,13 @@ export const schemaInputTypeRadioString = {
899
918
  required: ['has_siblings'],
900
919
  };
901
920
 
921
+ export const schemaInputTypeRadioStringY = {
922
+ properties: {
923
+ has_siblings: mockRadioInputStringY,
924
+ },
925
+ required: ['has_siblings'],
926
+ };
927
+
902
928
  export const schemaInputTypeRadioBoolean = {
903
929
  properties: {
904
930
  over_18: mockRadioInputBoolean,