@remoteoss/json-schema-form 0.8.2-dev.20240213105045 → 0.9.1-dev.20240320135936
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 +12 -0
- package/dist/index.cjs +18 -8
- package/dist/index.js +19 -9
- package/dist/standalone.js +18 -8
- package/package.json +1 -1
- package/src/tests/const.test.js +79 -3
- package/src/tests/helpers.js +4 -3
- package/src/tests/jsonLogic.fixtures.js +29 -0
- package/src/tests/jsonLogic.test.js +11 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
#### 0.9.0-beta.0 (2024-03-11)
|
|
2
|
+
|
|
3
|
+
##### Breaking changes
|
|
4
|
+
|
|
5
|
+
* Rename `value` -> `forcedValue`. This is in regards to the `json-logic`, where a "forced value" will now be returned in each relevant field (i.e. fields where the schema `const` and `default` are the same) with `forcedValue` over `value`. ([#66](https://github.com/remoteoss/json-schema-form/pull/66)) ([77c445a9](https://github.com/remoteoss/json-schema-form/commit/77c445a9dce657a7648642312f22c18f972187c7))
|
|
6
|
+
|
|
7
|
+
#### 0.8.2-beta.0 (2024-02-13)
|
|
8
|
+
|
|
9
|
+
##### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **helpers:** getFieldOptions - return empty array if oneOf missing in radio ([#67](https://github.com/remoteoss/json-schema-form/pull/67)) ([6511330f](https://github.com/remoteoss/json-schema-form/commit/6511330f55a2accedb1c58a61ff915a3a0186dbb))
|
|
12
|
+
|
|
1
13
|
#### 0.8.1-beta.0 (2024-02-12)
|
|
2
14
|
|
|
3
15
|
##### 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.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.9.1-dev.20240320135936
|
|
5
|
+
Generated: Wed, 20 Mar 2024 13:59:53 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -459,7 +459,7 @@ var validateMaxDate = (value, minDate) => {
|
|
|
459
459
|
};
|
|
460
460
|
var yupSchemas = {
|
|
461
461
|
text: validateOnlyStrings,
|
|
462
|
-
|
|
462
|
+
radioOrSelectString: (options) => {
|
|
463
463
|
return (0, import_yup.string)().nullable().transform((value) => {
|
|
464
464
|
if (value === "") {
|
|
465
465
|
return void 0;
|
|
@@ -519,6 +519,9 @@ var yupSchemas = {
|
|
|
519
519
|
}
|
|
520
520
|
return dateString;
|
|
521
521
|
},
|
|
522
|
+
radioOrSelectNumber: (options) => (0, import_yup.mixed)().typeError("The value must be a number").oneOf(options, ({ value }) => {
|
|
523
|
+
return `The option ${JSON.stringify(value)} is not valid.`;
|
|
524
|
+
}).nullable(),
|
|
522
525
|
number: (0, import_yup.number)().typeError("The value must be a number").nullable(),
|
|
523
526
|
file: (0, import_yup.array)().nullable(),
|
|
524
527
|
email: (0, import_yup.string)().trim().email("Please enter a valid email address").nullable(),
|
|
@@ -548,7 +551,9 @@ function getRequiredErrorMessage(inputType, { inlineError, configError }) {
|
|
|
548
551
|
return "Please acknowledge this field";
|
|
549
552
|
return "Required field";
|
|
550
553
|
}
|
|
551
|
-
var getJsonTypeInArray = (jsonType) =>
|
|
554
|
+
var getJsonTypeInArray = (jsonType) => {
|
|
555
|
+
return Array.isArray(jsonType) ? jsonType.find((val) => val !== "null") : jsonType;
|
|
556
|
+
};
|
|
552
557
|
var getOptions = (field) => {
|
|
553
558
|
const allValues = field.options?.map((option) => ({
|
|
554
559
|
value: option.value,
|
|
@@ -562,9 +567,13 @@ var getOptions = (field) => {
|
|
|
562
567
|
};
|
|
563
568
|
var getYupSchema = ({ inputType, ...field }) => {
|
|
564
569
|
const jsonType = getJsonTypeInArray(field.jsonType);
|
|
565
|
-
if (field.options?.length > 0) {
|
|
570
|
+
if (field.options?.length > 0 && field.jsonType !== "number") {
|
|
566
571
|
const optionValues = getOptions(field);
|
|
567
|
-
return yupSchemas.
|
|
572
|
+
return yupSchemas.radioOrSelectString(optionValues);
|
|
573
|
+
}
|
|
574
|
+
if (field.options?.length > 0 && field.jsonType === "number") {
|
|
575
|
+
const optionValues = getOptions(field).map((i) => i.value);
|
|
576
|
+
return yupSchemas.radioOrSelectNumber(optionValues);
|
|
568
577
|
}
|
|
569
578
|
if (field.format === "date") {
|
|
570
579
|
return yupSchemas.date({ minDate: field.minDate, maxDate: field.maxDate });
|
|
@@ -1381,7 +1390,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
1381
1390
|
const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
1382
1391
|
const description = presentation?.description || node.description;
|
|
1383
1392
|
const statementDescription = presentation.statement?.description;
|
|
1384
|
-
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? {
|
|
1393
|
+
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" && node.const === node.default ? { forcedValue: node.const } : {};
|
|
1385
1394
|
return (0, import_omitBy.default)(
|
|
1386
1395
|
{
|
|
1387
1396
|
const: node.const,
|
|
@@ -1477,9 +1486,10 @@ var handleValuesChange = (fields, jsonSchema, config, logic) => (values) => {
|
|
|
1477
1486
|
};
|
|
1478
1487
|
};
|
|
1479
1488
|
function getDecoratedComputedAttributes(computedAttributes) {
|
|
1489
|
+
const isEqualConstAndDefault = computedAttributes?.const === computedAttributes?.default;
|
|
1480
1490
|
return {
|
|
1481
1491
|
...computedAttributes ?? {},
|
|
1482
|
-
...computedAttributes?.const && computedAttributes?.default ? {
|
|
1492
|
+
...computedAttributes?.const && computedAttributes?.default && isEqualConstAndDefault ? { forcedValue: computedAttributes.const } : {}
|
|
1483
1493
|
};
|
|
1484
1494
|
}
|
|
1485
1495
|
|
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.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.9.1-dev.20240320135936
|
|
5
|
+
Generated: Wed, 20 Mar 2024 13:59:53 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -386,7 +386,7 @@ import jsonLogic from "json-logic-js";
|
|
|
386
386
|
import flow from "lodash/flow";
|
|
387
387
|
import noop from "lodash/noop";
|
|
388
388
|
import { randexp } from "randexp";
|
|
389
|
-
import { string, number, boolean, object, array } from "yup";
|
|
389
|
+
import { string, number, boolean, object, array, mixed } from "yup";
|
|
390
390
|
var DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
|
|
391
391
|
var baseString = string().trim();
|
|
392
392
|
var todayDateHint = (/* @__PURE__ */ new Date()).toISOString().substring(0, 10);
|
|
@@ -423,7 +423,7 @@ var validateMaxDate = (value, minDate) => {
|
|
|
423
423
|
};
|
|
424
424
|
var yupSchemas = {
|
|
425
425
|
text: validateOnlyStrings,
|
|
426
|
-
|
|
426
|
+
radioOrSelectString: (options) => {
|
|
427
427
|
return string().nullable().transform((value) => {
|
|
428
428
|
if (value === "") {
|
|
429
429
|
return void 0;
|
|
@@ -483,6 +483,9 @@ var yupSchemas = {
|
|
|
483
483
|
}
|
|
484
484
|
return dateString;
|
|
485
485
|
},
|
|
486
|
+
radioOrSelectNumber: (options) => mixed().typeError("The value must be a number").oneOf(options, ({ value }) => {
|
|
487
|
+
return `The option ${JSON.stringify(value)} is not valid.`;
|
|
488
|
+
}).nullable(),
|
|
486
489
|
number: number().typeError("The value must be a number").nullable(),
|
|
487
490
|
file: array().nullable(),
|
|
488
491
|
email: string().trim().email("Please enter a valid email address").nullable(),
|
|
@@ -512,7 +515,9 @@ function getRequiredErrorMessage(inputType, { inlineError, configError }) {
|
|
|
512
515
|
return "Please acknowledge this field";
|
|
513
516
|
return "Required field";
|
|
514
517
|
}
|
|
515
|
-
var getJsonTypeInArray = (jsonType) =>
|
|
518
|
+
var getJsonTypeInArray = (jsonType) => {
|
|
519
|
+
return Array.isArray(jsonType) ? jsonType.find((val) => val !== "null") : jsonType;
|
|
520
|
+
};
|
|
516
521
|
var getOptions = (field) => {
|
|
517
522
|
const allValues = field.options?.map((option) => ({
|
|
518
523
|
value: option.value,
|
|
@@ -526,9 +531,13 @@ var getOptions = (field) => {
|
|
|
526
531
|
};
|
|
527
532
|
var getYupSchema = ({ inputType, ...field }) => {
|
|
528
533
|
const jsonType = getJsonTypeInArray(field.jsonType);
|
|
529
|
-
if (field.options?.length > 0) {
|
|
534
|
+
if (field.options?.length > 0 && field.jsonType !== "number") {
|
|
530
535
|
const optionValues = getOptions(field);
|
|
531
|
-
return yupSchemas.
|
|
536
|
+
return yupSchemas.radioOrSelectString(optionValues);
|
|
537
|
+
}
|
|
538
|
+
if (field.options?.length > 0 && field.jsonType === "number") {
|
|
539
|
+
const optionValues = getOptions(field).map((i) => i.value);
|
|
540
|
+
return yupSchemas.radioOrSelectNumber(optionValues);
|
|
532
541
|
}
|
|
533
542
|
if (field.format === "date") {
|
|
534
543
|
return yupSchemas.date({ minDate: field.minDate, maxDate: field.maxDate });
|
|
@@ -1345,7 +1354,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
1345
1354
|
const node = omit(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
1346
1355
|
const description = presentation?.description || node.description;
|
|
1347
1356
|
const statementDescription = presentation.statement?.description;
|
|
1348
|
-
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? {
|
|
1357
|
+
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" && node.const === node.default ? { forcedValue: node.const } : {};
|
|
1349
1358
|
return omitBy(
|
|
1350
1359
|
{
|
|
1351
1360
|
const: node.const,
|
|
@@ -1441,9 +1450,10 @@ var handleValuesChange = (fields, jsonSchema, config, logic) => (values) => {
|
|
|
1441
1450
|
};
|
|
1442
1451
|
};
|
|
1443
1452
|
function getDecoratedComputedAttributes(computedAttributes) {
|
|
1453
|
+
const isEqualConstAndDefault = computedAttributes?.const === computedAttributes?.default;
|
|
1444
1454
|
return {
|
|
1445
1455
|
...computedAttributes ?? {},
|
|
1446
|
-
...computedAttributes?.const && computedAttributes?.default ? {
|
|
1456
|
+
...computedAttributes?.const && computedAttributes?.default && isEqualConstAndDefault ? { forcedValue: computedAttributes.const } : {}
|
|
1447
1457
|
};
|
|
1448
1458
|
}
|
|
1449
1459
|
|
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.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.9.1-dev.20240320135936
|
|
5
|
+
Generated: Wed, 20 Mar 2024 13:59:53 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -11777,7 +11777,7 @@ var validateMaxDate = (value, minDate) => {
|
|
|
11777
11777
|
};
|
|
11778
11778
|
var yupSchemas = {
|
|
11779
11779
|
text: validateOnlyStrings,
|
|
11780
|
-
|
|
11780
|
+
radioOrSelectString: (options) => {
|
|
11781
11781
|
return StringSchema().nullable().transform((value) => {
|
|
11782
11782
|
if (value === "") {
|
|
11783
11783
|
return void 0;
|
|
@@ -11837,6 +11837,9 @@ var yupSchemas = {
|
|
|
11837
11837
|
}
|
|
11838
11838
|
return dateString;
|
|
11839
11839
|
},
|
|
11840
|
+
radioOrSelectNumber: (options) => SchemaType().typeError("The value must be a number").oneOf(options, ({ value }) => {
|
|
11841
|
+
return `The option ${JSON.stringify(value)} is not valid.`;
|
|
11842
|
+
}).nullable(),
|
|
11840
11843
|
number: NumberSchema().typeError("The value must be a number").nullable(),
|
|
11841
11844
|
file: array_default().nullable(),
|
|
11842
11845
|
email: StringSchema().trim().email("Please enter a valid email address").nullable(),
|
|
@@ -11866,7 +11869,9 @@ function getRequiredErrorMessage(inputType, { inlineError, configError }) {
|
|
|
11866
11869
|
return "Please acknowledge this field";
|
|
11867
11870
|
return "Required field";
|
|
11868
11871
|
}
|
|
11869
|
-
var getJsonTypeInArray = (jsonType) =>
|
|
11872
|
+
var getJsonTypeInArray = (jsonType) => {
|
|
11873
|
+
return Array.isArray(jsonType) ? jsonType.find((val) => val !== "null") : jsonType;
|
|
11874
|
+
};
|
|
11870
11875
|
var getOptions = (field) => {
|
|
11871
11876
|
const allValues = field.options?.map((option) => ({
|
|
11872
11877
|
value: option.value,
|
|
@@ -11880,9 +11885,13 @@ var getOptions = (field) => {
|
|
|
11880
11885
|
};
|
|
11881
11886
|
var getYupSchema = ({ inputType, ...field }) => {
|
|
11882
11887
|
const jsonType = getJsonTypeInArray(field.jsonType);
|
|
11883
|
-
if (field.options?.length > 0) {
|
|
11888
|
+
if (field.options?.length > 0 && field.jsonType !== "number") {
|
|
11884
11889
|
const optionValues = getOptions(field);
|
|
11885
|
-
return yupSchemas.
|
|
11890
|
+
return yupSchemas.radioOrSelectString(optionValues);
|
|
11891
|
+
}
|
|
11892
|
+
if (field.options?.length > 0 && field.jsonType === "number") {
|
|
11893
|
+
const optionValues = getOptions(field).map((i) => i.value);
|
|
11894
|
+
return yupSchemas.radioOrSelectNumber(optionValues);
|
|
11886
11895
|
}
|
|
11887
11896
|
if (field.format === "date") {
|
|
11888
11897
|
return yupSchemas.date({ minDate: field.minDate, maxDate: field.maxDate });
|
|
@@ -12699,7 +12708,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
12699
12708
|
const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
12700
12709
|
const description = presentation?.description || node.description;
|
|
12701
12710
|
const statementDescription = presentation.statement?.description;
|
|
12702
|
-
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? {
|
|
12711
|
+
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" && node.const === node.default ? { forcedValue: node.const } : {};
|
|
12703
12712
|
return (0, import_omitBy.default)(
|
|
12704
12713
|
{
|
|
12705
12714
|
const: node.const,
|
|
@@ -12795,9 +12804,10 @@ var handleValuesChange = (fields, jsonSchema, config, logic) => (values2) => {
|
|
|
12795
12804
|
};
|
|
12796
12805
|
};
|
|
12797
12806
|
function getDecoratedComputedAttributes(computedAttributes) {
|
|
12807
|
+
const isEqualConstAndDefault = computedAttributes?.const === computedAttributes?.default;
|
|
12798
12808
|
return {
|
|
12799
12809
|
...computedAttributes ?? {},
|
|
12800
|
-
...computedAttributes?.const && computedAttributes?.default ? {
|
|
12810
|
+
...computedAttributes?.const && computedAttributes?.default && isEqualConstAndDefault ? { forcedValue: computedAttributes.const } : {}
|
|
12801
12811
|
};
|
|
12802
12812
|
}
|
|
12803
12813
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remoteoss/json-schema-form",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1-dev.20240320135936",
|
|
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",
|
package/src/tests/const.test.js
CHANGED
|
@@ -112,7 +112,7 @@ describe('validations: const', () => {
|
|
|
112
112
|
},
|
|
113
113
|
{ strictInputType: false }
|
|
114
114
|
);
|
|
115
|
-
expect(fields[0]).toMatchObject({
|
|
115
|
+
expect(fields[0]).toMatchObject({ forcedValue: 10, const: 10, default: 10 });
|
|
116
116
|
});
|
|
117
117
|
});
|
|
118
118
|
|
|
@@ -130,7 +130,7 @@ describe('const/default with forced values', () => {
|
|
|
130
130
|
expect(handleValidation({ zero_only: 1 }).formErrors).toEqual({
|
|
131
131
|
zero_only: 'The only accepted value is 0.',
|
|
132
132
|
});
|
|
133
|
-
expect(fields[0]).toMatchObject({
|
|
133
|
+
expect(fields[0]).toMatchObject({ forcedValue: 0, const: 0, default: 0 });
|
|
134
134
|
expect(handleValidation({ zero_only: 0 }).formErrors).toBeUndefined();
|
|
135
135
|
// null is also considered valid until we fix @BUG RMT-518
|
|
136
136
|
// Expectation: To fail with error "The only accepted value is 0."
|
|
@@ -151,9 +151,85 @@ describe('const/default with forced values', () => {
|
|
|
151
151
|
ten_only: 'The only accepted value is 10.',
|
|
152
152
|
});
|
|
153
153
|
expect(handleValidation({ ten_only: 10 }).formErrors).toBeUndefined();
|
|
154
|
-
expect(fields[0]).toMatchObject({
|
|
154
|
+
expect(fields[0]).toMatchObject({ forcedValue: 10, const: 10, default: 10 });
|
|
155
155
|
// null is also considered valid until we fix @BUG RMT-518
|
|
156
156
|
// Expectation: To fail with error "The only accepted value is 10."
|
|
157
157
|
expect(handleValidation({ ten_only: null }).formErrors).toBeUndefined();
|
|
158
158
|
});
|
|
159
|
+
|
|
160
|
+
it('do not set a forced value if const and default do not equal', () => {
|
|
161
|
+
const { fields } = createHeadlessForm(
|
|
162
|
+
{
|
|
163
|
+
properties: {
|
|
164
|
+
bad_field_for_number: { type: 'number', const: 10, default: 20 },
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
{ strictInputType: false }
|
|
168
|
+
);
|
|
169
|
+
expect(fields[0]).not.toMatchObject({ forcedValue: expect.any(Number) });
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('Should work numbers with non-standard input types', () => {
|
|
173
|
+
const { fields, handleValidation } = createHeadlessForm(
|
|
174
|
+
{
|
|
175
|
+
properties: {
|
|
176
|
+
number: {
|
|
177
|
+
type: 'integer',
|
|
178
|
+
const: 300,
|
|
179
|
+
default: 300,
|
|
180
|
+
'x-jsf-presentation': {
|
|
181
|
+
inputType: 'money',
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
required: ['number'],
|
|
186
|
+
},
|
|
187
|
+
{ strictInputType: true }
|
|
188
|
+
);
|
|
189
|
+
expect(handleValidation({ number: 0 }).formErrors).toEqual({
|
|
190
|
+
number: 'The only accepted value is 300.',
|
|
191
|
+
});
|
|
192
|
+
expect(handleValidation({ number: 300 }).formErrors).toBeUndefined();
|
|
193
|
+
expect(fields[0]).toMatchObject({ forcedValue: 300 });
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe('OneOf const', () => {
|
|
198
|
+
it('Validates numbers correctly', () => {
|
|
199
|
+
const { handleValidation } = createHeadlessForm(
|
|
200
|
+
{
|
|
201
|
+
properties: {
|
|
202
|
+
number: { type: 'number', oneOf: [{ const: 0 }, { const: 1 }, { const: 2 }] },
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
{ strictInputType: false }
|
|
206
|
+
);
|
|
207
|
+
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
208
|
+
expect(handleValidation({ number: 3 }).formErrors).toEqual({
|
|
209
|
+
number: 'The option 3 is not valid.',
|
|
210
|
+
});
|
|
211
|
+
expect(handleValidation({ number: 2 }).formErrors).toBeUndefined();
|
|
212
|
+
expect(handleValidation({ number: '2' }).formErrors).toEqual({
|
|
213
|
+
number: 'The option "2" is not valid.',
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('Validates strings', () => {
|
|
218
|
+
const { handleValidation } = createHeadlessForm(
|
|
219
|
+
{
|
|
220
|
+
properties: {
|
|
221
|
+
number: { type: 'number', oneOf: [{ const: 'a' }, { const: 'b' }, { const: 'c' }] },
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
{ strictInputType: false }
|
|
225
|
+
);
|
|
226
|
+
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
227
|
+
expect(handleValidation({ number: 'd' }).formErrors).toEqual({
|
|
228
|
+
number: 'The option "d" is not valid.',
|
|
229
|
+
});
|
|
230
|
+
expect(handleValidation({ number: 'a' }).formErrors).toBeUndefined();
|
|
231
|
+
expect(handleValidation({ number: '2' }).formErrors).toEqual({
|
|
232
|
+
number: 'The option "2" is not valid.',
|
|
233
|
+
});
|
|
234
|
+
});
|
|
159
235
|
});
|
package/src/tests/helpers.js
CHANGED
|
@@ -93,6 +93,7 @@ export const mockTextMaxLengthInput = {
|
|
|
93
93
|
export const mockRadioInputDeprecated = {
|
|
94
94
|
title: 'Has siblings',
|
|
95
95
|
description: 'Do you have any siblings?',
|
|
96
|
+
type: 'string',
|
|
96
97
|
enum: ['yes', 'no'],
|
|
97
98
|
'x-jsf-presentation': {
|
|
98
99
|
inputType: 'radio',
|
|
@@ -386,6 +387,7 @@ export const mockGroupArrayInput = {
|
|
|
386
387
|
],
|
|
387
388
|
},
|
|
388
389
|
title: 'Child Sex',
|
|
390
|
+
type: 'string',
|
|
389
391
|
},
|
|
390
392
|
},
|
|
391
393
|
'x-jsf-order': ['full_name', 'birthdate', 'sex'],
|
|
@@ -842,7 +844,7 @@ export const mockRadioInputOptionalNull = {
|
|
|
842
844
|
{ const: 'yes', title: 'Yes' },
|
|
843
845
|
{ const: 'no', title: 'No' },
|
|
844
846
|
// JSF excludes the null option from the field output
|
|
845
|
-
// But
|
|
847
|
+
// But keeps null as an accepted value
|
|
846
848
|
{ const: null, title: 'N/A' },
|
|
847
849
|
],
|
|
848
850
|
'x-jsf-presentation': { inputType: 'radio' },
|
|
@@ -1612,7 +1614,6 @@ export const schemaFieldsetScopedCondition = {
|
|
|
1612
1614
|
properties: {
|
|
1613
1615
|
has_child: {
|
|
1614
1616
|
description: 'If yes, it will show its age.',
|
|
1615
|
-
maximum: 100,
|
|
1616
1617
|
'x-jsf-presentation': {
|
|
1617
1618
|
inputType: 'radio',
|
|
1618
1619
|
options: [
|
|
@@ -1627,7 +1628,7 @@ export const schemaFieldsetScopedCondition = {
|
|
|
1627
1628
|
],
|
|
1628
1629
|
},
|
|
1629
1630
|
title: 'Do you have a child?',
|
|
1630
|
-
type: '
|
|
1631
|
+
type: 'string',
|
|
1631
1632
|
},
|
|
1632
1633
|
age: {
|
|
1633
1634
|
description: 'This age is required, but the "age" at the root level is still optional.',
|
|
@@ -227,6 +227,35 @@ export const schemaWithComputedAttributes = {
|
|
|
227
227
|
},
|
|
228
228
|
};
|
|
229
229
|
|
|
230
|
+
export const badSchemaThatWillNotSetAForcedValue = {
|
|
231
|
+
properties: {
|
|
232
|
+
field_a: {
|
|
233
|
+
type: 'number',
|
|
234
|
+
},
|
|
235
|
+
field_b: {
|
|
236
|
+
type: 'number',
|
|
237
|
+
'x-jsf-logic-computedAttrs': {
|
|
238
|
+
const: 'a_times_three',
|
|
239
|
+
default: 'a_times_two',
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
'x-jsf-logic': {
|
|
244
|
+
computedValues: {
|
|
245
|
+
a_times_two: {
|
|
246
|
+
rule: {
|
|
247
|
+
'*': [{ var: 'field_a' }, 2],
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
a_times_three: {
|
|
251
|
+
rule: {
|
|
252
|
+
'*': [{ var: 'field_a' }, 3],
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
|
|
230
259
|
export const schemaWithInlineRuleForComputedAttributeWithoutCopy = {
|
|
231
260
|
properties: {
|
|
232
261
|
field_a: {
|
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
schemaWithUnknownVariableInComputedValues,
|
|
36
36
|
schemaWithUnknownVariableInValidations,
|
|
37
37
|
schemaWithValidationThatDoesNotExistOnProperty,
|
|
38
|
+
badSchemaThatWillNotSetAForcedValue,
|
|
38
39
|
} from './jsonLogic.fixtures';
|
|
39
40
|
import { mockConsole, restoreConsoleAndEnsureItWasNotCalled } from './testUtils';
|
|
40
41
|
|
|
@@ -335,12 +336,21 @@ describe('jsonLogic: cross-values validations', () => {
|
|
|
335
336
|
'This field is 2 times bigger than field_a with value of 4.'
|
|
336
337
|
);
|
|
337
338
|
expect(fieldB.default).toEqual(4);
|
|
338
|
-
expect(fieldB.
|
|
339
|
+
expect(fieldB.forcedValue).toEqual(4);
|
|
339
340
|
handleValidation({ field_a: 4 });
|
|
340
341
|
expect(fieldB.default).toEqual(8);
|
|
341
342
|
expect(fieldB.label).toEqual('This is 8!');
|
|
342
343
|
});
|
|
343
344
|
|
|
345
|
+
it('A forced value will not be set when const and default are not equal', () => {
|
|
346
|
+
const { fields } = createHeadlessForm(badSchemaThatWillNotSetAForcedValue, {
|
|
347
|
+
strictInputType: false,
|
|
348
|
+
initialValues: { field_a: 2 },
|
|
349
|
+
});
|
|
350
|
+
expect(fields[1]).toMatchObject({ const: 6, default: 4 });
|
|
351
|
+
expect(fields[1]).not.toMatchObject({ forcedValue: expect.any(Number) });
|
|
352
|
+
});
|
|
353
|
+
|
|
344
354
|
it('Derived errorMessages and statements work', () => {
|
|
345
355
|
const { fields, handleValidation } = createHeadlessForm(
|
|
346
356
|
schemaWithComputedAttributesAndErrorMessages,
|