@remoteoss/json-schema-form 0.7.1-dev.20231026204916 → 0.7.2-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 +20 -22
- package/dist/index.cjs +37 -31
- package/dist/index.js +37 -31
- package/dist/standalone.js +37 -31
- package/package.json +1 -1
- package/src/tests/createHeadlessForm.test.js +62 -19
- package/src/tests/helpers.js +9 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
#### 0.7.2-beta.0 (2023-11-06)
|
|
2
|
+
|
|
3
|
+
##### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* **select/radio:** Support oneOf[].pattern validation ([#47](https://github.com/remoteoss/json-schema-form/pull/47)) ([5a4bb592](https://github.com/remoteoss/json-schema-form/commit/5a4bb59266ff595a9cb65f5b261a4ae2f3ad279f))
|
|
6
|
+
|
|
7
|
+
#### 0.7.1-beta.0 (2023-10-31)
|
|
8
|
+
|
|
9
|
+
##### Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **select:** support string type ([#54](https://github.com/remoteoss/json-schema-form/pull/54)) ([b00f8776](https://github.com/remoteoss/json-schema-form/commit/b00f8776aa244803375ba64fbdd52c8fff9b9bd8))
|
|
12
|
+
|
|
1
13
|
#### 0.7.0-beta.0 (2023-10-23)
|
|
2
14
|
|
|
3
15
|
##### Chores
|
|
@@ -27,10 +39,8 @@ BREAKING CHANGES:
|
|
|
27
39
|
|
|
28
40
|
- json-logic: Add conditional logic checking. ([#41](https://github.com/remoteoss/json-schema-form/pull/41)) ([6292b01e](https://github.com/remoteoss/json-schema-form/commit/6292b01e3f77a9038328d7375080ffc4cb30dbc8))
|
|
29
41
|
|
|
30
|
-
|
|
31
42
|
###### Full API additions now supported from 0.6.5 onwards.
|
|
32
43
|
|
|
33
|
-
|
|
34
44
|
- New custom JSON Schema keyword `x-jsf-logic` added to support cross-field validations. Built on top of [JsonLogic](https://jsonlogic.com/).
|
|
35
45
|
|
|
36
46
|
- `x-jsf-logic` can contain:
|
|
@@ -49,16 +59,11 @@ While docs are underway, you can read examples from all the [tests](https://gith
|
|
|
49
59
|
|
|
50
60
|
In short: `x-jsf-logic` is added to support complex conditional cross-field validations. Properties like `x-jsf-logic-validations` allow hooking those up to individual fields.
|
|
51
61
|
|
|
52
|
-
|
|
53
62
|
#### 0.6.4-beta.0 (2023-09-15)
|
|
54
63
|
|
|
55
|
-
|
|
56
|
-
|
|
57
64
|
##### Changes
|
|
58
|
-
- json-logic: computedAttrs - handle inline rules ([#40](https://github.com/remoteoss/json-schema-form/pull/40)) ([860ad91b](https://github.com/remoteoss/json-schema-form/commit/860ad91b034ab35d4d4bc51c0c04675f102bf278))
|
|
59
|
-
|
|
60
|
-
|
|
61
65
|
|
|
66
|
+
- json-logic: computedAttrs - handle inline rules ([#40](https://github.com/remoteoss/json-schema-form/pull/40)) ([860ad91b](https://github.com/remoteoss/json-schema-form/commit/860ad91b034ab35d4d4bc51c0c04675f102bf278))
|
|
62
67
|
|
|
63
68
|
#### 0.6.1-beta.0 (2023-09-13)
|
|
64
69
|
|
|
@@ -66,50 +71,43 @@ In short: `x-jsf-logic` is added to support complex conditional cross-field vali
|
|
|
66
71
|
|
|
67
72
|
- json-logic: Computed string based values ([#37](https://github.com/remoteoss/json-schema-form/pull/37)) ([6e042ea5](https://github.com/remoteoss/json-schema-form/commit/6e042ea579497ea573710c307a6ff7ee2f19b931))
|
|
68
73
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
74
|
#### 0.5.0-beta.0 (2023-09-12)
|
|
73
75
|
|
|
74
76
|
##### Changes
|
|
77
|
+
|
|
75
78
|
- json-logic: Computed Attributes ([#36](https://github.com/remoteoss/json-schema-form/pull/36)) ([80c29589](https://github.com/remoteoss/json-schema-form/commit/80c29589ac0972e0f33add70a59df15a46db1b43))
|
|
76
79
|
- json-logic: Initial skeleton implementation ([#35](https://github.com/remoteoss/json-schema-form/pull/35)) ([63149ae8](https://github.com/remoteoss/json-schema-form/commit/63149ae863cf1b5ad76a3b2a49c7f343e55ce07b))
|
|
77
80
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
81
|
#### 0.4.5-beta.0 (2023-08-31)
|
|
82
|
+
|
|
82
83
|
##### Bug fixes
|
|
83
84
|
|
|
84
85
|
- Validate values based on `const` key ([#34](https://github.com/remoteoss/json-schema-form/pull/34)) ([bf07870d](https://github.com/remoteoss/json-schema-form/commit/bf07870d407d9b9b078882a078b9e4c7928df868))
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
87
|
#### 0.4.4-beta.0 (2023-08-30)
|
|
90
88
|
|
|
91
89
|
##### Chores
|
|
92
90
|
|
|
93
|
-
|
|
91
|
+
- **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))
|
|
94
92
|
|
|
95
93
|
#### 0.4.3-beta.0 (2023-08-09)
|
|
96
94
|
|
|
97
95
|
##### Bug fixes
|
|
98
96
|
|
|
99
|
-
|
|
97
|
+
- **conditions:** Validate a deeply nested if (e.g. checking an object with a number property) in an if property now doesn't break the form. ([#33](https://github.com/remoteoss/json-schema-form/pull/33)) ([e34cfcc](https://github.com/remoteoss/json-schema-form/commit/e34cfccaf45f1460b346f3cff0c797b3d11259e3))
|
|
100
98
|
|
|
101
99
|
#### 0.4.2-beta.0 (2023-07-20)
|
|
102
100
|
|
|
103
101
|
##### Bug Fixes
|
|
104
102
|
|
|
105
|
-
|
|
103
|
+
- **date:** Validate based on minDate and maxDate ([#30](https://github.com/remoteoss/json-schema-form/pull/30)) ([01c0143e](https://github.com/remoteoss/json-schema-form/commit/01c0143ea4a3775f9489ae6cb8fd99a90b3f1394))
|
|
106
104
|
|
|
107
105
|
#### 0.4.1-beta.0 (2023-07-03)
|
|
108
106
|
|
|
109
107
|
##### Bug Fixes
|
|
110
108
|
|
|
111
|
-
|
|
112
|
-
|
|
109
|
+
- **fieldset:** support root conditionals for fieldsets ([#23](https://github.com/remoteoss/json-schema-form/pull/23)) ([65d87b3a](https://github.com/remoteoss/json-schema-form/commit/65d87b3a93018f0729aed565000eb2a2ce1f2ce7))
|
|
110
|
+
- **select/radio:** Accept just the values in options (plus `''` and `null` for backward-compatibility) ([#18](https://github.com/remoteoss/json-schema-form/pull/18)) ([37501d2d](https://github.com/remoteoss/json-schema-form/commit/37501d2ddafdd5e207b34d2ca3f6b7b7a1006e9d))
|
|
113
111
|
|
|
114
112
|
#### 0.4.0-beta.0 (2023-06-22)
|
|
115
113
|
|
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.7.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.7.2-beta.0
|
|
5
|
+
Generated: Mon, 06 Nov 2023 19:11:58 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -461,38 +461,43 @@ var validateMaxDate = (value, minDate) => {
|
|
|
461
461
|
};
|
|
462
462
|
var yupSchemas = {
|
|
463
463
|
text: validateOnlyStrings,
|
|
464
|
-
radioOrSelect: (options
|
|
465
|
-
if (
|
|
466
|
-
return
|
|
464
|
+
radioOrSelect: (options, isString) => {
|
|
465
|
+
if (isString) {
|
|
466
|
+
return (0, import_yup.string)().nullable();
|
|
467
467
|
}
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
return value === null ? void 0 : value;
|
|
472
|
-
}).test(
|
|
473
|
-
/*
|
|
474
|
-
Custom test determines if the value either:
|
|
475
|
-
- Matches a specific option by value
|
|
476
|
-
- Matches a pattern
|
|
477
|
-
If the option is undefined do not test, to allow for optional fields.
|
|
478
|
-
*/
|
|
479
|
-
"matchesOptionOrPattern",
|
|
480
|
-
({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
|
|
481
|
-
(value) => {
|
|
482
|
-
if (value === void 0) {
|
|
483
|
-
return true;
|
|
468
|
+
return (0, import_yup.string)().nullable().transform((value) => {
|
|
469
|
+
if (value === "") {
|
|
470
|
+
return void 0;
|
|
484
471
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
return true;
|
|
472
|
+
if (options?.some((option) => option.value === null)) {
|
|
473
|
+
return value;
|
|
488
474
|
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
475
|
+
return value === null ? void 0 : value;
|
|
476
|
+
}).test(
|
|
477
|
+
/*
|
|
478
|
+
Custom test determines if the value either:
|
|
479
|
+
- Matches a specific option by value
|
|
480
|
+
- Matches a pattern
|
|
481
|
+
If the option is undefined do not test, to allow for optional fields.
|
|
482
|
+
*/
|
|
483
|
+
"matchesOptionOrPattern",
|
|
484
|
+
({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
|
|
485
|
+
(value) => {
|
|
486
|
+
if (value === void 0) {
|
|
487
|
+
return true;
|
|
488
|
+
}
|
|
489
|
+
const exactMatch = options.some((option) => option.value === value);
|
|
490
|
+
if (exactMatch) {
|
|
491
|
+
return true;
|
|
492
|
+
}
|
|
493
|
+
const patternMatch = options.some((option) => option.pattern?.test(value));
|
|
494
|
+
if (patternMatch) {
|
|
495
|
+
return true;
|
|
496
|
+
}
|
|
497
|
+
return false;
|
|
492
498
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
),
|
|
499
|
+
);
|
|
500
|
+
},
|
|
496
501
|
date: ({ minDate, maxDate }) => {
|
|
497
502
|
let dateString = (0, import_yup.string)().nullable().transform((value) => {
|
|
498
503
|
if (value === "") {
|
|
@@ -563,8 +568,9 @@ var getOptions = (field) => {
|
|
|
563
568
|
var getYupSchema = ({ inputType, ...field }) => {
|
|
564
569
|
const jsonType = getJsonTypeInArray(field.jsonType);
|
|
565
570
|
if (field.options?.length > 0) {
|
|
571
|
+
const isString = field.options?.findIndex((option) => option.type === "string") > -1;
|
|
566
572
|
const optionValues = getOptions(field);
|
|
567
|
-
return yupSchemas.radioOrSelect(optionValues);
|
|
573
|
+
return yupSchemas.radioOrSelect(optionValues, isString);
|
|
568
574
|
}
|
|
569
575
|
if (field.format === "date") {
|
|
570
576
|
return yupSchemas.date({ minDate: field.minDate, maxDate: field.maxDate });
|
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.7.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.7.2-beta.0
|
|
5
|
+
Generated: Mon, 06 Nov 2023 19:11:58 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -425,38 +425,43 @@ var validateMaxDate = (value, minDate) => {
|
|
|
425
425
|
};
|
|
426
426
|
var yupSchemas = {
|
|
427
427
|
text: validateOnlyStrings,
|
|
428
|
-
radioOrSelect: (options
|
|
429
|
-
if (
|
|
430
|
-
return
|
|
428
|
+
radioOrSelect: (options, isString) => {
|
|
429
|
+
if (isString) {
|
|
430
|
+
return string().nullable();
|
|
431
431
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
return value === null ? void 0 : value;
|
|
436
|
-
}).test(
|
|
437
|
-
/*
|
|
438
|
-
Custom test determines if the value either:
|
|
439
|
-
- Matches a specific option by value
|
|
440
|
-
- Matches a pattern
|
|
441
|
-
If the option is undefined do not test, to allow for optional fields.
|
|
442
|
-
*/
|
|
443
|
-
"matchesOptionOrPattern",
|
|
444
|
-
({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
|
|
445
|
-
(value) => {
|
|
446
|
-
if (value === void 0) {
|
|
447
|
-
return true;
|
|
432
|
+
return string().nullable().transform((value) => {
|
|
433
|
+
if (value === "") {
|
|
434
|
+
return void 0;
|
|
448
435
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
return true;
|
|
436
|
+
if (options?.some((option) => option.value === null)) {
|
|
437
|
+
return value;
|
|
452
438
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
439
|
+
return value === null ? void 0 : value;
|
|
440
|
+
}).test(
|
|
441
|
+
/*
|
|
442
|
+
Custom test determines if the value either:
|
|
443
|
+
- Matches a specific option by value
|
|
444
|
+
- Matches a pattern
|
|
445
|
+
If the option is undefined do not test, to allow for optional fields.
|
|
446
|
+
*/
|
|
447
|
+
"matchesOptionOrPattern",
|
|
448
|
+
({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
|
|
449
|
+
(value) => {
|
|
450
|
+
if (value === void 0) {
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
453
|
+
const exactMatch = options.some((option) => option.value === value);
|
|
454
|
+
if (exactMatch) {
|
|
455
|
+
return true;
|
|
456
|
+
}
|
|
457
|
+
const patternMatch = options.some((option) => option.pattern?.test(value));
|
|
458
|
+
if (patternMatch) {
|
|
459
|
+
return true;
|
|
460
|
+
}
|
|
461
|
+
return false;
|
|
456
462
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
),
|
|
463
|
+
);
|
|
464
|
+
},
|
|
460
465
|
date: ({ minDate, maxDate }) => {
|
|
461
466
|
let dateString = string().nullable().transform((value) => {
|
|
462
467
|
if (value === "") {
|
|
@@ -527,8 +532,9 @@ var getOptions = (field) => {
|
|
|
527
532
|
var getYupSchema = ({ inputType, ...field }) => {
|
|
528
533
|
const jsonType = getJsonTypeInArray(field.jsonType);
|
|
529
534
|
if (field.options?.length > 0) {
|
|
535
|
+
const isString = field.options?.findIndex((option) => option.type === "string") > -1;
|
|
530
536
|
const optionValues = getOptions(field);
|
|
531
|
-
return yupSchemas.radioOrSelect(optionValues);
|
|
537
|
+
return yupSchemas.radioOrSelect(optionValues, isString);
|
|
532
538
|
}
|
|
533
539
|
if (field.format === "date") {
|
|
534
540
|
return yupSchemas.date({ minDate: field.minDate, maxDate: field.maxDate });
|
package/dist/standalone.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.7.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.7.2-beta.0
|
|
5
|
+
Generated: Mon, 06 Nov 2023 19:11:58 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -11779,38 +11779,43 @@ var validateMaxDate = (value, minDate) => {
|
|
|
11779
11779
|
};
|
|
11780
11780
|
var yupSchemas = {
|
|
11781
11781
|
text: validateOnlyStrings,
|
|
11782
|
-
radioOrSelect: (options
|
|
11783
|
-
if (
|
|
11784
|
-
return
|
|
11782
|
+
radioOrSelect: (options, isString2) => {
|
|
11783
|
+
if (isString2) {
|
|
11784
|
+
return StringSchema().nullable();
|
|
11785
11785
|
}
|
|
11786
|
-
|
|
11787
|
-
|
|
11788
|
-
|
|
11789
|
-
return value === null ? void 0 : value;
|
|
11790
|
-
}).test(
|
|
11791
|
-
/*
|
|
11792
|
-
Custom test determines if the value either:
|
|
11793
|
-
- Matches a specific option by value
|
|
11794
|
-
- Matches a pattern
|
|
11795
|
-
If the option is undefined do not test, to allow for optional fields.
|
|
11796
|
-
*/
|
|
11797
|
-
"matchesOptionOrPattern",
|
|
11798
|
-
({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
|
|
11799
|
-
(value) => {
|
|
11800
|
-
if (value === void 0) {
|
|
11801
|
-
return true;
|
|
11786
|
+
return StringSchema().nullable().transform((value) => {
|
|
11787
|
+
if (value === "") {
|
|
11788
|
+
return void 0;
|
|
11802
11789
|
}
|
|
11803
|
-
|
|
11804
|
-
|
|
11805
|
-
return true;
|
|
11790
|
+
if (options?.some((option) => option.value === null)) {
|
|
11791
|
+
return value;
|
|
11806
11792
|
}
|
|
11807
|
-
|
|
11808
|
-
|
|
11809
|
-
|
|
11793
|
+
return value === null ? void 0 : value;
|
|
11794
|
+
}).test(
|
|
11795
|
+
/*
|
|
11796
|
+
Custom test determines if the value either:
|
|
11797
|
+
- Matches a specific option by value
|
|
11798
|
+
- Matches a pattern
|
|
11799
|
+
If the option is undefined do not test, to allow for optional fields.
|
|
11800
|
+
*/
|
|
11801
|
+
"matchesOptionOrPattern",
|
|
11802
|
+
({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
|
|
11803
|
+
(value) => {
|
|
11804
|
+
if (value === void 0) {
|
|
11805
|
+
return true;
|
|
11806
|
+
}
|
|
11807
|
+
const exactMatch = options.some((option) => option.value === value);
|
|
11808
|
+
if (exactMatch) {
|
|
11809
|
+
return true;
|
|
11810
|
+
}
|
|
11811
|
+
const patternMatch = options.some((option) => option.pattern?.test(value));
|
|
11812
|
+
if (patternMatch) {
|
|
11813
|
+
return true;
|
|
11814
|
+
}
|
|
11815
|
+
return false;
|
|
11810
11816
|
}
|
|
11811
|
-
|
|
11812
|
-
|
|
11813
|
-
),
|
|
11817
|
+
);
|
|
11818
|
+
},
|
|
11814
11819
|
date: ({ minDate, maxDate }) => {
|
|
11815
11820
|
let dateString = StringSchema().nullable().transform((value) => {
|
|
11816
11821
|
if (value === "") {
|
|
@@ -11881,8 +11886,9 @@ var getOptions = (field) => {
|
|
|
11881
11886
|
var getYupSchema = ({ inputType, ...field }) => {
|
|
11882
11887
|
const jsonType = getJsonTypeInArray(field.jsonType);
|
|
11883
11888
|
if (field.options?.length > 0) {
|
|
11889
|
+
const isString2 = field.options?.findIndex((option) => option.type === "string") > -1;
|
|
11884
11890
|
const optionValues = getOptions(field);
|
|
11885
|
-
return yupSchemas.radioOrSelect(optionValues);
|
|
11891
|
+
return yupSchemas.radioOrSelect(optionValues, isString2);
|
|
11886
11892
|
}
|
|
11887
11893
|
if (field.format === "date") {
|
|
11888
11894
|
return yupSchemas.date({ minDate: field.minDate, maxDate: field.maxDate });
|
package/package.json
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
schemaInputTypeRadioOptionsWithDetails,
|
|
16
16
|
schemaInputTypeSelectSoloDeprecated,
|
|
17
17
|
schemaInputTypeSelectSolo,
|
|
18
|
+
schemaInputTypeSelectString,
|
|
18
19
|
schemaInputTypeSelectMultipleDeprecated,
|
|
19
20
|
schemaInputTypeSelectMultiple,
|
|
20
21
|
schemaInputTypeSelectMultipleOptional,
|
|
@@ -431,7 +432,7 @@ describe('createHeadlessForm', () => {
|
|
|
431
432
|
});
|
|
432
433
|
|
|
433
434
|
describe('field support', () => {
|
|
434
|
-
function assertOptionsAllowed({ handleValidation, fieldName, validOptions }) {
|
|
435
|
+
function assertOptionsAllowed({ handleValidation, fieldName, validOptions, isString = false }) {
|
|
435
436
|
const validateForm = (vals) => friendlyError(handleValidation(vals));
|
|
436
437
|
|
|
437
438
|
// All allowed options are valid
|
|
@@ -439,27 +440,34 @@ describe('createHeadlessForm', () => {
|
|
|
439
440
|
expect(validateForm({ [fieldName]: value })).toBeUndefined();
|
|
440
441
|
});
|
|
441
442
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
[fieldName]: '
|
|
445
|
-
|
|
443
|
+
if (!isString) {
|
|
444
|
+
// Any other arbitrary value is not valid.
|
|
445
|
+
expect(validateForm({ [fieldName]: 'blah-blah' })).toEqual({
|
|
446
|
+
[fieldName]: 'The option "blah-blah" is not valid.',
|
|
447
|
+
});
|
|
446
448
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
449
|
+
// Given undefined, it says it's a required field.
|
|
450
|
+
expect(validateForm({})).toEqual({
|
|
451
|
+
[fieldName]: 'Required field',
|
|
452
|
+
});
|
|
451
453
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
454
|
+
// As required field, empty string ("") is also considered empty. @BUG RMT-518
|
|
455
|
+
// Expectation: The error to be "The option '' is not valid."
|
|
456
|
+
expect(validateForm({ [fieldName]: '' })).toEqual({
|
|
457
|
+
[fieldName]: 'Required field',
|
|
458
|
+
});
|
|
457
459
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
460
|
+
// As required field, null is also considered empty @BUG RMT-518
|
|
461
|
+
// Expectation: The error to be "The option null is not valid."
|
|
462
|
+
expect(validateForm({ [fieldName]: null })).toEqual({
|
|
463
|
+
[fieldName]: 'Required field',
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
if (isString) {
|
|
468
|
+
// Any other arbitrary value is valid.
|
|
469
|
+
expect(validateForm({ [fieldName]: 'blah-blah' })).toBeUndefined();
|
|
470
|
+
}
|
|
463
471
|
}
|
|
464
472
|
|
|
465
473
|
it('support "text" field type', () => {
|
|
@@ -631,6 +639,41 @@ describe('createHeadlessForm', () => {
|
|
|
631
639
|
});
|
|
632
640
|
});
|
|
633
641
|
|
|
642
|
+
it('supports "select" field type with string option', () => {
|
|
643
|
+
const { fields, handleValidation } = createHeadlessForm(schemaInputTypeSelectString);
|
|
644
|
+
const fieldSelect = fields[0];
|
|
645
|
+
expect(fieldSelect).toMatchObject({
|
|
646
|
+
name: 'browsers',
|
|
647
|
+
label: 'Browsers (solo)',
|
|
648
|
+
description: 'This solo select also includes a disabled option.',
|
|
649
|
+
options: [
|
|
650
|
+
{
|
|
651
|
+
value: 'chr',
|
|
652
|
+
label: 'Chrome',
|
|
653
|
+
},
|
|
654
|
+
{
|
|
655
|
+
value: 'ff',
|
|
656
|
+
label: 'Firefox',
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
value: 'ie',
|
|
660
|
+
label: 'Internet Explorer',
|
|
661
|
+
disabled: true,
|
|
662
|
+
},
|
|
663
|
+
{ value: undefined, type: 'string', label: '{Create another}' },
|
|
664
|
+
],
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
expect(fieldSelect).not.toHaveProperty('multiple');
|
|
668
|
+
|
|
669
|
+
assertOptionsAllowed({
|
|
670
|
+
handleValidation,
|
|
671
|
+
fieldName: 'browsers',
|
|
672
|
+
validOptions: ['chr', 'ff', 'ie'],
|
|
673
|
+
isString: true,
|
|
674
|
+
});
|
|
675
|
+
});
|
|
676
|
+
|
|
634
677
|
it('supports "select" field type with multiple options @deprecated', () => {
|
|
635
678
|
const result = createHeadlessForm(schemaInputTypeSelectMultipleDeprecated);
|
|
636
679
|
expect(result).toMatchObject({
|
package/src/tests/helpers.js
CHANGED
|
@@ -238,6 +238,11 @@ export const mockSelectInputSolo = {
|
|
|
238
238
|
},
|
|
239
239
|
};
|
|
240
240
|
|
|
241
|
+
export const mockSelectInputSoloCreatable = {
|
|
242
|
+
...mockSelectInputSolo,
|
|
243
|
+
oneOf: [...mockSelectInputSolo.oneOf, { type: 'string', title: '{Create another}' }],
|
|
244
|
+
};
|
|
245
|
+
|
|
241
246
|
export const mockSelectInputMultiple = {
|
|
242
247
|
title: 'Browsers (multiple)',
|
|
243
248
|
description: 'This multi-select also includes a disabled option.',
|
|
@@ -937,6 +942,10 @@ export const schemaInputTypeSelectSolo = JSONSchemaBuilder()
|
|
|
937
942
|
.setRequiredFields(['browsers'])
|
|
938
943
|
.build();
|
|
939
944
|
|
|
945
|
+
export const schemaInputTypeSelectString = JSONSchemaBuilder().addInput({
|
|
946
|
+
browsers: mockSelectInputSoloCreatable,
|
|
947
|
+
});
|
|
948
|
+
|
|
940
949
|
/** @deprecated */
|
|
941
950
|
export const schemaInputTypeSelectMultipleDeprecated = JSONSchemaBuilder()
|
|
942
951
|
.addInput({
|