@remoteoss/json-schema-form 0.11.7-dev.20241120091537 → 0.11.9-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 +18 -0
- package/dist/index.cjs +12 -4
- package/dist/index.js +12 -4
- package/dist/standalone.js +12 -4
- package/package.json +1 -1
- package/src/tests/checkIfConditionMatches.test.js +8 -0
- package/src/tests/conditions.test.js +68 -0
- package/src/tests/createHeadlessForm.test.js +40 -0
- package/src/tests/helpers.js +26 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
#### 0.11.9-beta.0 (2024-12-17)
|
|
2
|
+
|
|
3
|
+
##### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* Add support for boolean values in the if condition ([#100](https://github.com/remoteoss/json-schema-form/pull/100)) ([b3dca67d](https://github.com/remoteoss/json-schema-form/commit/b3dca67da14a7e4f5339a14a1e2f14ac014d2b92))
|
|
6
|
+
|
|
7
|
+
#### 0.11.8-beta.0 (2024-11-20)
|
|
8
|
+
|
|
9
|
+
##### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **integer:** support integer field type ([#11](https://github.com/remoteoss/json-schema-form/pull/11)) ([14f34971](https://github.com/remoteoss/json-schema-form/commit/14f349714ce7b294ae710801168b017692c659af))
|
|
12
|
+
|
|
13
|
+
#### 0.11.7-beta.0 (2024-11-14)
|
|
14
|
+
|
|
15
|
+
##### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* **validation:** validate radio with string-y types; ([#94](https://github.com/remoteoss/json-schema-form/pull/94)) ([606913d8](https://github.com/remoteoss/json-schema-form/commit/606913d8412a02d9a38a43e903add58b8e11a7e4))
|
|
18
|
+
|
|
1
19
|
#### 0.11.6-beta.0 (2024-10-15)
|
|
2
20
|
|
|
3
21
|
##### Bug Fixes
|
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.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.11.9-beta.0
|
|
5
|
+
Generated: Tue, 17 Dec 2024 08:59:12 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -98,6 +98,9 @@ function hasProperty(object2, propertyName) {
|
|
|
98
98
|
|
|
99
99
|
// src/checkIfConditionMatches.js
|
|
100
100
|
function checkIfConditionMatchesProperties(node, formValues, formFields, logic) {
|
|
101
|
+
if (typeof node.if === "boolean") {
|
|
102
|
+
return node.if;
|
|
103
|
+
}
|
|
101
104
|
return Object.keys(node.if.properties ?? {}).every((name) => {
|
|
102
105
|
const currentProperty = node.if.properties[name];
|
|
103
106
|
const value = formValues[name];
|
|
@@ -481,7 +484,12 @@ var yupSchemas = {
|
|
|
481
484
|
}).test(
|
|
482
485
|
"matchesOptionOrPattern",
|
|
483
486
|
({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
|
|
484
|
-
(
|
|
487
|
+
(castValue, { originalValue }) => {
|
|
488
|
+
if (castValue !== void 0 && typeof originalValue !== "string") {
|
|
489
|
+
return false;
|
|
490
|
+
}
|
|
491
|
+
return validateRadioOrSelectOptions(castValue, options);
|
|
492
|
+
}
|
|
485
493
|
);
|
|
486
494
|
},
|
|
487
495
|
date: ({ minDate, maxDate }) => {
|
|
@@ -1308,7 +1316,7 @@ function processNode({
|
|
|
1308
1316
|
parentID
|
|
1309
1317
|
});
|
|
1310
1318
|
});
|
|
1311
|
-
if (node.if) {
|
|
1319
|
+
if (node.if !== void 0) {
|
|
1312
1320
|
const matchesCondition = checkIfConditionMatchesProperties(node, formValues, formFields, logic);
|
|
1313
1321
|
if (matchesCondition && node.then) {
|
|
1314
1322
|
const { required: branchRequired } = processNode({
|
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.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.11.9-beta.0
|
|
5
|
+
Generated: Tue, 17 Dec 2024 08:59:12 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -61,6 +61,9 @@ function hasProperty(object2, propertyName) {
|
|
|
61
61
|
|
|
62
62
|
// src/checkIfConditionMatches.js
|
|
63
63
|
function checkIfConditionMatchesProperties(node, formValues, formFields, logic) {
|
|
64
|
+
if (typeof node.if === "boolean") {
|
|
65
|
+
return node.if;
|
|
66
|
+
}
|
|
64
67
|
return Object.keys(node.if.properties ?? {}).every((name) => {
|
|
65
68
|
const currentProperty = node.if.properties[name];
|
|
66
69
|
const value = formValues[name];
|
|
@@ -444,7 +447,12 @@ var yupSchemas = {
|
|
|
444
447
|
}).test(
|
|
445
448
|
"matchesOptionOrPattern",
|
|
446
449
|
({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
|
|
447
|
-
(
|
|
450
|
+
(castValue, { originalValue }) => {
|
|
451
|
+
if (castValue !== void 0 && typeof originalValue !== "string") {
|
|
452
|
+
return false;
|
|
453
|
+
}
|
|
454
|
+
return validateRadioOrSelectOptions(castValue, options);
|
|
455
|
+
}
|
|
448
456
|
);
|
|
449
457
|
},
|
|
450
458
|
date: ({ minDate, maxDate }) => {
|
|
@@ -1271,7 +1279,7 @@ function processNode({
|
|
|
1271
1279
|
parentID
|
|
1272
1280
|
});
|
|
1273
1281
|
});
|
|
1274
|
-
if (node.if) {
|
|
1282
|
+
if (node.if !== void 0) {
|
|
1275
1283
|
const matchesCondition = checkIfConditionMatchesProperties(node, formValues, formFields, logic);
|
|
1276
1284
|
if (matchesCondition && node.then) {
|
|
1277
1285
|
const { required: branchRequired } = processNode({
|
package/dist/standalone.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.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.11.9-beta.0
|
|
5
|
+
Generated: Tue, 17 Dec 2024 08:59:12 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -11578,6 +11578,9 @@ function hasProperty(object2, propertyName) {
|
|
|
11578
11578
|
|
|
11579
11579
|
// src/checkIfConditionMatches.js
|
|
11580
11580
|
function checkIfConditionMatchesProperties(node, formValues, formFields, logic) {
|
|
11581
|
+
if (typeof node.if === "boolean") {
|
|
11582
|
+
return node.if;
|
|
11583
|
+
}
|
|
11581
11584
|
return Object.keys(node.if.properties ?? {}).every((name) => {
|
|
11582
11585
|
const currentProperty = node.if.properties[name];
|
|
11583
11586
|
const value = formValues[name];
|
|
@@ -11960,7 +11963,12 @@ var yupSchemas = {
|
|
|
11960
11963
|
}).test(
|
|
11961
11964
|
"matchesOptionOrPattern",
|
|
11962
11965
|
({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
|
|
11963
|
-
(
|
|
11966
|
+
(castValue, { originalValue }) => {
|
|
11967
|
+
if (castValue !== void 0 && typeof originalValue !== "string") {
|
|
11968
|
+
return false;
|
|
11969
|
+
}
|
|
11970
|
+
return validateRadioOrSelectOptions(castValue, options);
|
|
11971
|
+
}
|
|
11964
11972
|
);
|
|
11965
11973
|
},
|
|
11966
11974
|
date: ({ minDate, maxDate }) => {
|
|
@@ -12787,7 +12795,7 @@ function processNode({
|
|
|
12787
12795
|
parentID
|
|
12788
12796
|
});
|
|
12789
12797
|
});
|
|
12790
|
-
if (node.if) {
|
|
12798
|
+
if (node.if !== void 0) {
|
|
12791
12799
|
const matchesCondition = checkIfConditionMatchesProperties(node, formValues, formFields, logic);
|
|
12792
12800
|
if (matchesCondition && node.then) {
|
|
12793
12801
|
const { required: branchRequired } = processNode({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remoteoss/json-schema-form",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.9-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",
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { checkIfConditionMatchesProperties } from '../checkIfConditionMatches';
|
|
2
2
|
|
|
3
|
+
it('True if is always going to be true', () => {
|
|
4
|
+
expect(checkIfConditionMatchesProperties({ if: true })).toBe(true);
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
it('False if is always going to be false', () => {
|
|
8
|
+
expect(checkIfConditionMatchesProperties({ if: false })).toBe(false);
|
|
9
|
+
});
|
|
10
|
+
|
|
3
11
|
it('Empty if is always going to be true', () => {
|
|
4
12
|
expect(checkIfConditionMatchesProperties({ if: { properties: {} } })).toBe(true);
|
|
5
13
|
});
|
|
@@ -479,3 +479,71 @@ describe('Conditional with a minimum value check', () => {
|
|
|
479
479
|
expect(handleValidation({ salary: 1000, reason: 'reason_one' }).formErrors).toEqual(undefined);
|
|
480
480
|
});
|
|
481
481
|
});
|
|
482
|
+
|
|
483
|
+
describe('Conditional with literal booleans', () => {
|
|
484
|
+
it('handles true case', () => {
|
|
485
|
+
const schema = {
|
|
486
|
+
properties: {
|
|
487
|
+
is_full_time: {
|
|
488
|
+
type: 'boolean',
|
|
489
|
+
},
|
|
490
|
+
salary: {
|
|
491
|
+
type: 'number',
|
|
492
|
+
},
|
|
493
|
+
},
|
|
494
|
+
required: [],
|
|
495
|
+
if: true,
|
|
496
|
+
then: {
|
|
497
|
+
required: ['is_full_time'],
|
|
498
|
+
},
|
|
499
|
+
else: {
|
|
500
|
+
required: ['salary'],
|
|
501
|
+
},
|
|
502
|
+
};
|
|
503
|
+
const { fields, handleValidation } = createHeadlessForm(schema, { strictInputType: false });
|
|
504
|
+
|
|
505
|
+
handleValidation({});
|
|
506
|
+
|
|
507
|
+
expect(fields[0]).toMatchObject({
|
|
508
|
+
name: 'is_full_time',
|
|
509
|
+
required: true,
|
|
510
|
+
});
|
|
511
|
+
expect(fields[1]).toMatchObject({
|
|
512
|
+
name: 'salary',
|
|
513
|
+
required: false,
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
it('handles false case', () => {
|
|
518
|
+
const schema = {
|
|
519
|
+
properties: {
|
|
520
|
+
is_full_time: {
|
|
521
|
+
type: 'boolean',
|
|
522
|
+
},
|
|
523
|
+
salary: {
|
|
524
|
+
type: 'number',
|
|
525
|
+
},
|
|
526
|
+
},
|
|
527
|
+
required: [],
|
|
528
|
+
if: false,
|
|
529
|
+
then: {
|
|
530
|
+
required: ['is_full_time'],
|
|
531
|
+
},
|
|
532
|
+
else: {
|
|
533
|
+
required: ['salary'],
|
|
534
|
+
},
|
|
535
|
+
};
|
|
536
|
+
const { fields, handleValidation } = createHeadlessForm(schema, { strictInputType: false });
|
|
537
|
+
|
|
538
|
+
handleValidation({});
|
|
539
|
+
|
|
540
|
+
expect(fields[0]).toMatchObject({
|
|
541
|
+
name: 'is_full_time',
|
|
542
|
+
required: false,
|
|
543
|
+
});
|
|
544
|
+
expect(fields[1]).toMatchObject({
|
|
545
|
+
name: 'salary',
|
|
546
|
+
required: true,
|
|
547
|
+
});
|
|
548
|
+
});
|
|
549
|
+
});
|
|
@@ -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,
|
|
@@ -821,6 +822,45 @@ describe('createHeadlessForm', () => {
|
|
|
821
822
|
});
|
|
822
823
|
});
|
|
823
824
|
|
|
825
|
+
// @BUG COD-1859
|
|
826
|
+
// it should validate when type is string but value is not a boolean
|
|
827
|
+
it('support "radio" field string-y type', () => {
|
|
828
|
+
const { fields, handleValidation } = createHeadlessForm(schemaInputTypeRadioStringY);
|
|
829
|
+
|
|
830
|
+
const validateForm = (vals) => friendlyError(handleValidation(vals));
|
|
831
|
+
|
|
832
|
+
expect(fields).toMatchObject([
|
|
833
|
+
{
|
|
834
|
+
description: 'Do you have any siblings?',
|
|
835
|
+
label: 'Has siblings',
|
|
836
|
+
name: 'has_siblings',
|
|
837
|
+
options: [
|
|
838
|
+
{
|
|
839
|
+
label: 'Yes',
|
|
840
|
+
value: 'true',
|
|
841
|
+
},
|
|
842
|
+
{
|
|
843
|
+
label: 'No',
|
|
844
|
+
value: 'false',
|
|
845
|
+
},
|
|
846
|
+
],
|
|
847
|
+
required: true,
|
|
848
|
+
schema: expect.any(Object),
|
|
849
|
+
type: 'radio',
|
|
850
|
+
},
|
|
851
|
+
]);
|
|
852
|
+
|
|
853
|
+
assertOptionsAllowed({
|
|
854
|
+
handleValidation,
|
|
855
|
+
fieldName: 'has_siblings',
|
|
856
|
+
validOptions: ['true', 'false'],
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
expect(validateForm({ has_siblings: false })).toEqual({
|
|
860
|
+
has_siblings: 'The option "false" is not valid.',
|
|
861
|
+
});
|
|
862
|
+
});
|
|
863
|
+
|
|
824
864
|
it('support "radio" field number type', () => {
|
|
825
865
|
const { fields, handleValidation } = createHeadlessForm(schemaInputTypeRadioNumber);
|
|
826
866
|
|
package/src/tests/helpers.js
CHANGED
|
@@ -163,6 +163,25 @@ export const mockRadioInputBoolean = {
|
|
|
163
163
|
type: 'boolean',
|
|
164
164
|
};
|
|
165
165
|
|
|
166
|
+
export const mockRadioInputStringY = {
|
|
167
|
+
title: 'Has siblings',
|
|
168
|
+
description: 'Do you have any siblings?',
|
|
169
|
+
oneOf: [
|
|
170
|
+
{
|
|
171
|
+
title: 'Yes',
|
|
172
|
+
const: 'true',
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
title: 'No',
|
|
176
|
+
const: 'false',
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
'x-jsf-presentation': {
|
|
180
|
+
inputType: 'radio',
|
|
181
|
+
},
|
|
182
|
+
type: 'string',
|
|
183
|
+
};
|
|
184
|
+
|
|
166
185
|
export const mockRadioInputNumber = {
|
|
167
186
|
title: 'Number of siblings',
|
|
168
187
|
description: 'How many siblings do you have?',
|
|
@@ -914,6 +933,13 @@ export const schemaInputTypeRadioString = {
|
|
|
914
933
|
required: ['has_siblings'],
|
|
915
934
|
};
|
|
916
935
|
|
|
936
|
+
export const schemaInputTypeRadioStringY = {
|
|
937
|
+
properties: {
|
|
938
|
+
has_siblings: mockRadioInputStringY,
|
|
939
|
+
},
|
|
940
|
+
required: ['has_siblings'],
|
|
941
|
+
};
|
|
942
|
+
|
|
917
943
|
export const schemaInputTypeRadioBoolean = {
|
|
918
944
|
properties: {
|
|
919
945
|
over_18: mockRadioInputBoolean,
|