@remoteoss/json-schema-form 0.7.0-dev.20230928101050 → 0.7.1-dev.20231026204916
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 +23 -0
- package/dist/index.cjs +35 -10
- package/dist/index.js +35 -10
- package/dist/standalone.js +35 -10
- package/package.json +1 -1
- package/src/tests/const.test.js +61 -0
- package/src/tests/createHeadlessForm.test.js +49 -3
- package/src/tests/helpers.js +65 -80
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
#### 0.7.0-beta.0 (2023-10-23)
|
|
2
|
+
|
|
3
|
+
##### Chores
|
|
4
|
+
|
|
5
|
+
BREAKING CHANGES:
|
|
6
|
+
|
|
7
|
+
- **Description/Extra/Statement fields:** We have removed the sorrounding spans that we output in these fields ([#17](https://github.com/remoteoss/json-schema-form/pull/27)) ([6257533](https://github.com/remoteoss/json-schema-form/commit/6257533bead9c0f7391f240c2e5bacc801a90af7))
|
|
8
|
+
|
|
9
|
+
```diff
|
|
10
|
+
-description: '<span class="jsf-description">Write in <b>hh:ss</b> format</span>',
|
|
11
|
+
+description: 'Write in <b>hh:ss</b> format',
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
#### 0.6.6-beta.0 (2023-10-17)
|
|
15
|
+
|
|
16
|
+
##### Chores
|
|
17
|
+
|
|
18
|
+
- **github:** Add template for issues and pull requests ([#45](https://github.com/remoteoss/json-schema-form/pull/45)) ([621e3338](https://github.com/remoteoss/json-schema-form/commit/621e33389638541e771d2229c91655e430ea7ec4))
|
|
19
|
+
|
|
20
|
+
##### Bug Fixes
|
|
21
|
+
|
|
22
|
+
- allow 0 in const validation ([#48](https://github.com/remoteoss/json-schema-form/pull/48)) ([cde19fc9](https://github.com/remoteoss/json-schema-form/commit/cde19fc960c4eacdde476ddcdd8c650a4ff5ce96))
|
|
23
|
+
|
|
1
24
|
#### 0.6.5-beta.0 (2023-09-18)
|
|
2
25
|
|
|
3
26
|
##### Changes
|
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: Thu,
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.7.1-dev.20231026204916
|
|
5
|
+
Generated: Thu, 26 Oct 2023 20:49:34 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -465,13 +465,34 @@ var yupSchemas = {
|
|
|
465
465
|
if (value === "") {
|
|
466
466
|
return void 0;
|
|
467
467
|
}
|
|
468
|
-
if (options?.
|
|
468
|
+
if (options?.some((option) => option.value === null)) {
|
|
469
469
|
return value;
|
|
470
470
|
}
|
|
471
471
|
return value === null ? void 0 : value;
|
|
472
|
-
}).
|
|
473
|
-
|
|
474
|
-
|
|
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;
|
|
484
|
+
}
|
|
485
|
+
const exactMatch = options.some((option) => option.value === value);
|
|
486
|
+
if (exactMatch) {
|
|
487
|
+
return true;
|
|
488
|
+
}
|
|
489
|
+
const patternMatch = options.some((option) => option.pattern?.test(value));
|
|
490
|
+
if (patternMatch) {
|
|
491
|
+
return true;
|
|
492
|
+
}
|
|
493
|
+
return false;
|
|
494
|
+
}
|
|
495
|
+
),
|
|
475
496
|
date: ({ minDate, maxDate }) => {
|
|
476
497
|
let dateString = (0, import_yup.string)().nullable().transform((value) => {
|
|
477
498
|
if (value === "") {
|
|
@@ -529,12 +550,15 @@ function getRequiredErrorMessage(inputType, { inlineError, configError }) {
|
|
|
529
550
|
}
|
|
530
551
|
var getJsonTypeInArray = (jsonType) => Array.isArray(jsonType) ? jsonType.find((val) => val !== "null") : jsonType;
|
|
531
552
|
var getOptions = (field) => {
|
|
532
|
-
const allValues = field.options?.map((option) =>
|
|
553
|
+
const allValues = field.options?.map((option) => ({
|
|
554
|
+
value: option.value,
|
|
555
|
+
pattern: option.pattern ? new RegExp(option.pattern) : null
|
|
556
|
+
}));
|
|
533
557
|
const isOptionalWithNull = Array.isArray(field.jsonType) && // @TODO should also check the "oneOf" directly looking for "null"
|
|
534
558
|
// option but we don't have direct access at this point.
|
|
535
559
|
// Otherwise the JSON Schema validator will fail as explained in PR#18
|
|
536
560
|
field.jsonType.includes("null");
|
|
537
|
-
return isOptionalWithNull ? [...allValues, null] : allValues;
|
|
561
|
+
return isOptionalWithNull ? [...allValues, { option: null }] : allValues;
|
|
538
562
|
};
|
|
539
563
|
var getYupSchema = ({ inputType, ...field }) => {
|
|
540
564
|
const jsonType = getJsonTypeInArray(field.jsonType);
|
|
@@ -694,7 +718,7 @@ function buildYupSchema(field, config, logic) {
|
|
|
694
718
|
if (propertyFields.accept) {
|
|
695
719
|
validators.push(withFileFormat);
|
|
696
720
|
}
|
|
697
|
-
if (propertyFields.const) {
|
|
721
|
+
if (typeof propertyFields.const !== "undefined") {
|
|
698
722
|
validators.push(withConst);
|
|
699
723
|
}
|
|
700
724
|
if (propertyFields.jsonLogicValidations) {
|
|
@@ -1323,10 +1347,11 @@ function extractParametersFromNode(schemaNode) {
|
|
|
1323
1347
|
const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
1324
1348
|
const description = presentation?.description || node.description;
|
|
1325
1349
|
const statementDescription = presentation.statement?.description;
|
|
1350
|
+
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? { value: node.const } : {};
|
|
1326
1351
|
return (0, import_omitBy.default)(
|
|
1327
1352
|
{
|
|
1328
1353
|
const: node.const,
|
|
1329
|
-
...
|
|
1354
|
+
...value,
|
|
1330
1355
|
label: node.title,
|
|
1331
1356
|
readOnly: node.readOnly,
|
|
1332
1357
|
...node.deprecated && {
|
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: Thu,
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.7.1-dev.20231026204916
|
|
5
|
+
Generated: Thu, 26 Oct 2023 20:49:34 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -429,13 +429,34 @@ var yupSchemas = {
|
|
|
429
429
|
if (value === "") {
|
|
430
430
|
return void 0;
|
|
431
431
|
}
|
|
432
|
-
if (options?.
|
|
432
|
+
if (options?.some((option) => option.value === null)) {
|
|
433
433
|
return value;
|
|
434
434
|
}
|
|
435
435
|
return value === null ? void 0 : value;
|
|
436
|
-
}).
|
|
437
|
-
|
|
438
|
-
|
|
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;
|
|
448
|
+
}
|
|
449
|
+
const exactMatch = options.some((option) => option.value === value);
|
|
450
|
+
if (exactMatch) {
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
453
|
+
const patternMatch = options.some((option) => option.pattern?.test(value));
|
|
454
|
+
if (patternMatch) {
|
|
455
|
+
return true;
|
|
456
|
+
}
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
),
|
|
439
460
|
date: ({ minDate, maxDate }) => {
|
|
440
461
|
let dateString = string().nullable().transform((value) => {
|
|
441
462
|
if (value === "") {
|
|
@@ -493,12 +514,15 @@ function getRequiredErrorMessage(inputType, { inlineError, configError }) {
|
|
|
493
514
|
}
|
|
494
515
|
var getJsonTypeInArray = (jsonType) => Array.isArray(jsonType) ? jsonType.find((val) => val !== "null") : jsonType;
|
|
495
516
|
var getOptions = (field) => {
|
|
496
|
-
const allValues = field.options?.map((option) =>
|
|
517
|
+
const allValues = field.options?.map((option) => ({
|
|
518
|
+
value: option.value,
|
|
519
|
+
pattern: option.pattern ? new RegExp(option.pattern) : null
|
|
520
|
+
}));
|
|
497
521
|
const isOptionalWithNull = Array.isArray(field.jsonType) && // @TODO should also check the "oneOf" directly looking for "null"
|
|
498
522
|
// option but we don't have direct access at this point.
|
|
499
523
|
// Otherwise the JSON Schema validator will fail as explained in PR#18
|
|
500
524
|
field.jsonType.includes("null");
|
|
501
|
-
return isOptionalWithNull ? [...allValues, null] : allValues;
|
|
525
|
+
return isOptionalWithNull ? [...allValues, { option: null }] : allValues;
|
|
502
526
|
};
|
|
503
527
|
var getYupSchema = ({ inputType, ...field }) => {
|
|
504
528
|
const jsonType = getJsonTypeInArray(field.jsonType);
|
|
@@ -658,7 +682,7 @@ function buildYupSchema(field, config, logic) {
|
|
|
658
682
|
if (propertyFields.accept) {
|
|
659
683
|
validators.push(withFileFormat);
|
|
660
684
|
}
|
|
661
|
-
if (propertyFields.const) {
|
|
685
|
+
if (typeof propertyFields.const !== "undefined") {
|
|
662
686
|
validators.push(withConst);
|
|
663
687
|
}
|
|
664
688
|
if (propertyFields.jsonLogicValidations) {
|
|
@@ -1287,10 +1311,11 @@ function extractParametersFromNode(schemaNode) {
|
|
|
1287
1311
|
const node = omit(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
1288
1312
|
const description = presentation?.description || node.description;
|
|
1289
1313
|
const statementDescription = presentation.statement?.description;
|
|
1314
|
+
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? { value: node.const } : {};
|
|
1290
1315
|
return omitBy(
|
|
1291
1316
|
{
|
|
1292
1317
|
const: node.const,
|
|
1293
|
-
...
|
|
1318
|
+
...value,
|
|
1294
1319
|
label: node.title,
|
|
1295
1320
|
readOnly: node.readOnly,
|
|
1296
1321
|
...node.deprecated && {
|
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: Thu,
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.7.1-dev.20231026204916
|
|
5
|
+
Generated: Thu, 26 Oct 2023 20:49:34 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -11783,13 +11783,34 @@ var yupSchemas = {
|
|
|
11783
11783
|
if (value === "") {
|
|
11784
11784
|
return void 0;
|
|
11785
11785
|
}
|
|
11786
|
-
if (options?.
|
|
11786
|
+
if (options?.some((option) => option.value === null)) {
|
|
11787
11787
|
return value;
|
|
11788
11788
|
}
|
|
11789
11789
|
return value === null ? void 0 : value;
|
|
11790
|
-
}).
|
|
11791
|
-
|
|
11792
|
-
|
|
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;
|
|
11802
|
+
}
|
|
11803
|
+
const exactMatch = options.some((option) => option.value === value);
|
|
11804
|
+
if (exactMatch) {
|
|
11805
|
+
return true;
|
|
11806
|
+
}
|
|
11807
|
+
const patternMatch = options.some((option) => option.pattern?.test(value));
|
|
11808
|
+
if (patternMatch) {
|
|
11809
|
+
return true;
|
|
11810
|
+
}
|
|
11811
|
+
return false;
|
|
11812
|
+
}
|
|
11813
|
+
),
|
|
11793
11814
|
date: ({ minDate, maxDate }) => {
|
|
11794
11815
|
let dateString = StringSchema().nullable().transform((value) => {
|
|
11795
11816
|
if (value === "") {
|
|
@@ -11847,12 +11868,15 @@ function getRequiredErrorMessage(inputType, { inlineError, configError }) {
|
|
|
11847
11868
|
}
|
|
11848
11869
|
var getJsonTypeInArray = (jsonType) => Array.isArray(jsonType) ? jsonType.find((val) => val !== "null") : jsonType;
|
|
11849
11870
|
var getOptions = (field) => {
|
|
11850
|
-
const allValues = field.options?.map((option) =>
|
|
11871
|
+
const allValues = field.options?.map((option) => ({
|
|
11872
|
+
value: option.value,
|
|
11873
|
+
pattern: option.pattern ? new RegExp(option.pattern) : null
|
|
11874
|
+
}));
|
|
11851
11875
|
const isOptionalWithNull = Array.isArray(field.jsonType) && // @TODO should also check the "oneOf" directly looking for "null"
|
|
11852
11876
|
// option but we don't have direct access at this point.
|
|
11853
11877
|
// Otherwise the JSON Schema validator will fail as explained in PR#18
|
|
11854
11878
|
field.jsonType.includes("null");
|
|
11855
|
-
return isOptionalWithNull ? [...allValues, null] : allValues;
|
|
11879
|
+
return isOptionalWithNull ? [...allValues, { option: null }] : allValues;
|
|
11856
11880
|
};
|
|
11857
11881
|
var getYupSchema = ({ inputType, ...field }) => {
|
|
11858
11882
|
const jsonType = getJsonTypeInArray(field.jsonType);
|
|
@@ -12012,7 +12036,7 @@ function buildYupSchema(field, config, logic) {
|
|
|
12012
12036
|
if (propertyFields.accept) {
|
|
12013
12037
|
validators.push(withFileFormat);
|
|
12014
12038
|
}
|
|
12015
|
-
if (propertyFields.const) {
|
|
12039
|
+
if (typeof propertyFields.const !== "undefined") {
|
|
12016
12040
|
validators.push(withConst);
|
|
12017
12041
|
}
|
|
12018
12042
|
if (propertyFields.jsonLogicValidations) {
|
|
@@ -12641,10 +12665,11 @@ function extractParametersFromNode(schemaNode) {
|
|
|
12641
12665
|
const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
12642
12666
|
const description = presentation?.description || node.description;
|
|
12643
12667
|
const statementDescription = presentation.statement?.description;
|
|
12668
|
+
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? { value: node.const } : {};
|
|
12644
12669
|
return (0, import_omitBy.default)(
|
|
12645
12670
|
{
|
|
12646
12671
|
const: node.const,
|
|
12647
|
-
...
|
|
12672
|
+
...value,
|
|
12648
12673
|
label: node.title,
|
|
12649
12674
|
readOnly: node.readOnly,
|
|
12650
12675
|
...node.deprecated && {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remoteoss/json-schema-form",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1-dev.20231026204916",
|
|
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
|
@@ -20,6 +20,25 @@ describe('validations: const', () => {
|
|
|
20
20
|
expect(handleValidation({ ten_only: null }).formErrors).toBeUndefined();
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
+
it('Should work for when the number is 0', () => {
|
|
24
|
+
const { handleValidation } = createHeadlessForm(
|
|
25
|
+
{
|
|
26
|
+
properties: {
|
|
27
|
+
zero_only: { type: 'number', const: 0 },
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{ strictInputType: false }
|
|
31
|
+
);
|
|
32
|
+
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
33
|
+
expect(handleValidation({ zero_only: 1 }).formErrors).toEqual({
|
|
34
|
+
zero_only: 'The only accepted value is 0.',
|
|
35
|
+
});
|
|
36
|
+
expect(handleValidation({ zero_only: 0 }).formErrors).toBeUndefined();
|
|
37
|
+
// null is also considered valid until we fix @BUG RMT-518
|
|
38
|
+
// Expectation: To fail with error "The only accepted value is 0."
|
|
39
|
+
expect(handleValidation({ zero_only: null }).formErrors).toBeUndefined();
|
|
40
|
+
});
|
|
41
|
+
|
|
23
42
|
it('Should work for text', () => {
|
|
24
43
|
const { handleValidation } = createHeadlessForm(
|
|
25
44
|
{
|
|
@@ -96,3 +115,45 @@ describe('validations: const', () => {
|
|
|
96
115
|
expect(fields[0]).toMatchObject({ value: 10, const: 10, default: 10 });
|
|
97
116
|
});
|
|
98
117
|
});
|
|
118
|
+
|
|
119
|
+
describe('const/default with forced values', () => {
|
|
120
|
+
it('Should work for when the number is 0', () => {
|
|
121
|
+
const { fields, handleValidation } = createHeadlessForm(
|
|
122
|
+
{
|
|
123
|
+
properties: {
|
|
124
|
+
zero_only: { type: 'number', const: 0, default: 0 },
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
{ strictInputType: false }
|
|
128
|
+
);
|
|
129
|
+
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
130
|
+
expect(handleValidation({ zero_only: 1 }).formErrors).toEqual({
|
|
131
|
+
zero_only: 'The only accepted value is 0.',
|
|
132
|
+
});
|
|
133
|
+
expect(fields[0]).toMatchObject({ value: 0, const: 0, default: 0 });
|
|
134
|
+
expect(handleValidation({ zero_only: 0 }).formErrors).toBeUndefined();
|
|
135
|
+
// null is also considered valid until we fix @BUG RMT-518
|
|
136
|
+
// Expectation: To fail with error "The only accepted value is 0."
|
|
137
|
+
expect(handleValidation({ zero_only: null }).formErrors).toBeUndefined();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('Should work for number', () => {
|
|
141
|
+
const { fields, handleValidation } = createHeadlessForm(
|
|
142
|
+
{
|
|
143
|
+
properties: {
|
|
144
|
+
ten_only: { type: 'number', const: 10, default: 10 },
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
{ strictInputType: false }
|
|
148
|
+
);
|
|
149
|
+
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
150
|
+
expect(handleValidation({ ten_only: 1 }).formErrors).toEqual({
|
|
151
|
+
ten_only: 'The only accepted value is 10.',
|
|
152
|
+
});
|
|
153
|
+
expect(handleValidation({ ten_only: 10 }).formErrors).toBeUndefined();
|
|
154
|
+
expect(fields[0]).toMatchObject({ value: 10, const: 10, default: 10 });
|
|
155
|
+
// null is also considered valid until we fix @BUG RMT-518
|
|
156
|
+
// Expectation: To fail with error "The only accepted value is 10."
|
|
157
|
+
expect(handleValidation({ ten_only: null }).formErrors).toBeUndefined();
|
|
158
|
+
});
|
|
159
|
+
});
|
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
mockFileInput,
|
|
39
39
|
mockRadioCardInput,
|
|
40
40
|
mockRadioCardExpandableInput,
|
|
41
|
+
mockTelWithPattern,
|
|
41
42
|
mockTextInput,
|
|
42
43
|
mockTextInputDeprecated,
|
|
43
44
|
mockNumberInput,
|
|
@@ -1442,6 +1443,51 @@ describe('createHeadlessForm', () => {
|
|
|
1442
1443
|
});
|
|
1443
1444
|
});
|
|
1444
1445
|
|
|
1446
|
+
it('supports oneOf pattern validation', () => {
|
|
1447
|
+
const result = createHeadlessForm(mockTelWithPattern);
|
|
1448
|
+
|
|
1449
|
+
expect(result).toMatchObject({
|
|
1450
|
+
fields: [
|
|
1451
|
+
{
|
|
1452
|
+
label: 'Phone number',
|
|
1453
|
+
name: 'phone_number',
|
|
1454
|
+
type: 'tel',
|
|
1455
|
+
required: false,
|
|
1456
|
+
options: [
|
|
1457
|
+
{
|
|
1458
|
+
label: 'Portugal',
|
|
1459
|
+
pattern: '^(\\+351)[0-9]{9,}$',
|
|
1460
|
+
},
|
|
1461
|
+
{
|
|
1462
|
+
label: 'United Kingdom (UK)',
|
|
1463
|
+
pattern: '^(\\+44)[0-9]{1,}$',
|
|
1464
|
+
},
|
|
1465
|
+
{
|
|
1466
|
+
label: 'Bolivia',
|
|
1467
|
+
pattern: '^(\\+591)[0-9]{9,}$',
|
|
1468
|
+
},
|
|
1469
|
+
{
|
|
1470
|
+
label: 'Canada',
|
|
1471
|
+
pattern: '^(\\+1)(206|224)[0-9]{1,}$',
|
|
1472
|
+
},
|
|
1473
|
+
{
|
|
1474
|
+
label: 'United States',
|
|
1475
|
+
pattern: '^(\\+1)[0-9]{1,}$',
|
|
1476
|
+
},
|
|
1477
|
+
],
|
|
1478
|
+
},
|
|
1479
|
+
],
|
|
1480
|
+
});
|
|
1481
|
+
|
|
1482
|
+
const fieldValidator = result.fields[0].schema;
|
|
1483
|
+
|
|
1484
|
+
expect(fieldValidator.isValidSync('+351123123123')).toBe(true);
|
|
1485
|
+
expect(() => fieldValidator.validateSync('+35100')).toThrowError(
|
|
1486
|
+
'The option "+35100" is not valid.'
|
|
1487
|
+
);
|
|
1488
|
+
expect(fieldValidator.isValidSync(undefined)).toBe(true);
|
|
1489
|
+
});
|
|
1490
|
+
|
|
1445
1491
|
describe('supports "fieldset" field type', () => {
|
|
1446
1492
|
it('supports basic case', () => {
|
|
1447
1493
|
const result = createHeadlessForm({
|
|
@@ -1947,9 +1993,9 @@ describe('createHeadlessForm', () => {
|
|
|
1947
1993
|
},
|
|
1948
1994
|
},
|
|
1949
1995
|
{
|
|
1950
|
-
name: '
|
|
1951
|
-
label: '
|
|
1952
|
-
type: '
|
|
1996
|
+
name: 'role',
|
|
1997
|
+
label: 'Role',
|
|
1998
|
+
type: 'text',
|
|
1953
1999
|
statement: {
|
|
1954
2000
|
description: 'This is another statement message, but more severe.',
|
|
1955
2001
|
inputType: 'statement',
|
package/src/tests/helpers.js
CHANGED
|
@@ -453,6 +453,46 @@ export const mockCheckboxInput = {
|
|
|
453
453
|
type: 'string',
|
|
454
454
|
};
|
|
455
455
|
|
|
456
|
+
export const mockTelWithPattern = {
|
|
457
|
+
properties: {
|
|
458
|
+
phone_number: {
|
|
459
|
+
title: 'Phone number',
|
|
460
|
+
description: 'Enter your telephone number',
|
|
461
|
+
type: 'string',
|
|
462
|
+
'x-jsf-presentation': {
|
|
463
|
+
inputType: 'tel',
|
|
464
|
+
},
|
|
465
|
+
oneOf: [
|
|
466
|
+
{
|
|
467
|
+
title: 'Portugal',
|
|
468
|
+
pattern: '^(\\+351)[0-9]{9,}$',
|
|
469
|
+
'x-jsf-presentation': { meta: { countryCode: '351' } },
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
title: 'United Kingdom (UK)',
|
|
473
|
+
pattern: '^(\\+44)[0-9]{1,}$',
|
|
474
|
+
'x-jsf-presentation': { meta: { countryCode: '44' } },
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
title: 'Bolivia',
|
|
478
|
+
pattern: '^(\\+591)[0-9]{9,}$',
|
|
479
|
+
'x-jsf-presentation': { meta: { countryCode: '591' } },
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
title: 'Canada',
|
|
483
|
+
pattern: '^(\\+1)(206|224)[0-9]{1,}$',
|
|
484
|
+
'x-jsf-presentation': { meta: { countryCode: '1' } },
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
title: 'United States',
|
|
488
|
+
pattern: '^(\\+1)[0-9]{1,}$',
|
|
489
|
+
'x-jsf-presentation': { meta: { countryCode: '1' } },
|
|
490
|
+
},
|
|
491
|
+
],
|
|
492
|
+
},
|
|
493
|
+
},
|
|
494
|
+
};
|
|
495
|
+
|
|
456
496
|
/**
|
|
457
497
|
* Compose a schema with lower chance of human error
|
|
458
498
|
* @param {Object} schema version
|
|
@@ -463,6 +503,12 @@ export const mockCheckboxInput = {
|
|
|
463
503
|
})
|
|
464
504
|
.build();
|
|
465
505
|
*/
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* @deprecated in favor of normal JSON schema.
|
|
509
|
+
* Why? This adds extra complexity to read and to
|
|
510
|
+
* copy-paste into the Playground, validators, etc
|
|
511
|
+
* */
|
|
466
512
|
export function JSONSchemaBuilder() {
|
|
467
513
|
return {
|
|
468
514
|
addInput: function addInput(input) {
|
|
@@ -658,15 +704,15 @@ export const schemaWithoutTypes = {
|
|
|
658
704
|
},
|
|
659
705
|
};
|
|
660
706
|
|
|
661
|
-
export const schemaInputTypeText =
|
|
662
|
-
|
|
707
|
+
export const schemaInputTypeText = {
|
|
708
|
+
properties: {
|
|
663
709
|
id_number: mockTextInput,
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
|
|
710
|
+
},
|
|
711
|
+
required: ['id_number'],
|
|
712
|
+
};
|
|
667
713
|
|
|
668
|
-
export const schemaInputWithStatement =
|
|
669
|
-
|
|
714
|
+
export const schemaInputWithStatement = {
|
|
715
|
+
properties: {
|
|
670
716
|
bonus: {
|
|
671
717
|
title: 'Bonus',
|
|
672
718
|
'x-jsf-presentation': {
|
|
@@ -678,71 +724,10 @@ export const schemaInputWithStatement = JSONSchemaBuilder()
|
|
|
678
724
|
},
|
|
679
725
|
},
|
|
680
726
|
},
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
a_or_b: {
|
|
684
|
-
title: 'A dropdown',
|
|
685
|
-
description: 'Some options to chose from',
|
|
686
|
-
items: {
|
|
687
|
-
enum: ['A', 'B'],
|
|
688
|
-
},
|
|
727
|
+
role: {
|
|
728
|
+
title: 'Role',
|
|
689
729
|
'x-jsf-presentation': {
|
|
690
|
-
inputType: 'select',
|
|
691
|
-
options: [
|
|
692
|
-
{
|
|
693
|
-
label: 'A',
|
|
694
|
-
value: 'A',
|
|
695
|
-
},
|
|
696
|
-
{
|
|
697
|
-
label: 'B',
|
|
698
|
-
value: 'B',
|
|
699
|
-
},
|
|
700
|
-
],
|
|
701
|
-
placeholder: 'Select...',
|
|
702
|
-
statement: {
|
|
703
|
-
description: 'This is another statement message, but more severe.',
|
|
704
|
-
inputType: 'statement',
|
|
705
|
-
severity: 'warning',
|
|
706
|
-
},
|
|
707
|
-
},
|
|
708
|
-
},
|
|
709
|
-
})
|
|
710
|
-
.build();
|
|
711
|
-
|
|
712
|
-
export const schemaInputWithStatementDeprecated = JSONSchemaBuilder()
|
|
713
|
-
.addInput({
|
|
714
|
-
bonus: {
|
|
715
|
-
title: 'Bonus',
|
|
716
|
-
presentation: {
|
|
717
730
|
inputType: 'text',
|
|
718
|
-
statement: {
|
|
719
|
-
description: 'This is a custom statement message.',
|
|
720
|
-
inputType: 'statement',
|
|
721
|
-
severity: 'info',
|
|
722
|
-
},
|
|
723
|
-
},
|
|
724
|
-
},
|
|
725
|
-
})
|
|
726
|
-
.addInput({
|
|
727
|
-
a_or_b: {
|
|
728
|
-
title: 'A dropdown',
|
|
729
|
-
description: 'Some options to chose from',
|
|
730
|
-
items: {
|
|
731
|
-
enum: ['A', 'B'],
|
|
732
|
-
},
|
|
733
|
-
presentation: {
|
|
734
|
-
inputType: 'select',
|
|
735
|
-
options: [
|
|
736
|
-
{
|
|
737
|
-
label: 'A',
|
|
738
|
-
value: 'A',
|
|
739
|
-
},
|
|
740
|
-
{
|
|
741
|
-
label: 'B',
|
|
742
|
-
value: 'B',
|
|
743
|
-
},
|
|
744
|
-
],
|
|
745
|
-
placeholder: 'Select...',
|
|
746
731
|
statement: {
|
|
747
732
|
description: 'This is another statement message, but more severe.',
|
|
748
733
|
inputType: 'statement',
|
|
@@ -750,11 +735,11 @@ export const schemaInputWithStatementDeprecated = JSONSchemaBuilder()
|
|
|
750
735
|
},
|
|
751
736
|
},
|
|
752
737
|
},
|
|
753
|
-
}
|
|
754
|
-
|
|
738
|
+
},
|
|
739
|
+
};
|
|
755
740
|
|
|
756
|
-
export const schemaInputWithExtra =
|
|
757
|
-
|
|
741
|
+
export const schemaInputWithExtra = {
|
|
742
|
+
properties: {
|
|
758
743
|
bonus: {
|
|
759
744
|
title: 'Bonus',
|
|
760
745
|
'x-jsf-presentation': {
|
|
@@ -772,11 +757,11 @@ export const schemaInputWithExtra = JSONSchemaBuilder()
|
|
|
772
757
|
`,
|
|
773
758
|
},
|
|
774
759
|
},
|
|
775
|
-
}
|
|
776
|
-
|
|
760
|
+
},
|
|
761
|
+
};
|
|
777
762
|
|
|
778
|
-
export const schemaInputWithCustomDescription =
|
|
779
|
-
|
|
763
|
+
export const schemaInputWithCustomDescription = {
|
|
764
|
+
properties: {
|
|
780
765
|
other: {
|
|
781
766
|
title: 'Other',
|
|
782
767
|
'x-jsf-presentation': {
|
|
@@ -785,8 +770,8 @@ export const schemaInputWithCustomDescription = JSONSchemaBuilder()
|
|
|
785
770
|
},
|
|
786
771
|
type: 'string',
|
|
787
772
|
},
|
|
788
|
-
}
|
|
789
|
-
|
|
773
|
+
},
|
|
774
|
+
};
|
|
790
775
|
|
|
791
776
|
export const schemaInputDeprecated = JSONSchemaBuilder()
|
|
792
777
|
.addInput({
|