@remoteoss/json-schema-form 0.4.1-dev.20230702181843 → 0.4.1-dev.20230703161935
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 +20 -8
- package/dist/index.js +20 -8
- package/dist/standalone.js +20 -8
- package/package.json +1 -1
- package/src/tests/createHeadlessForm.test.js +22 -14
- package/src/tests/helpers.custom.js +1 -1
- package/src/tests/helpers.js +2 -2
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.4.1-dev.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.4.1-dev.20230703161935
|
|
5
|
+
Generated: Mon, 03 Jul 2023 16:19:50 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -422,18 +422,30 @@ function getRequiredErrorMessage(inputType, { inlineError, configError }) {
|
|
|
422
422
|
var getJsonTypeInArray = (jsonType) => Array.isArray(jsonType) ? jsonType.find((val) => val !== "null") : jsonType;
|
|
423
423
|
var getOptionsAllowed = (field) => {
|
|
424
424
|
const onlyValues = field.options?.map((option) => option.value);
|
|
425
|
-
const optionsBroken = [
|
|
425
|
+
const optionsBroken = [
|
|
426
|
+
...onlyValues,
|
|
427
|
+
""
|
|
428
|
+
// [1]
|
|
429
|
+
];
|
|
426
430
|
if (field.required) {
|
|
427
|
-
return
|
|
431
|
+
return [
|
|
432
|
+
...optionsBroken,
|
|
433
|
+
null
|
|
434
|
+
// [2]
|
|
435
|
+
];
|
|
428
436
|
}
|
|
429
|
-
const isOptionalWithNull = Array.isArray(field.jsonType) && // @TODO should also check the "oneOf" directly looking for "null"
|
|
430
|
-
// but we don't have direct access at this point.
|
|
431
|
-
// the JSON Schema validator will fail
|
|
437
|
+
const isOptionalWithNull = Array.isArray(field.jsonType) && // @TODO should also check the "oneOf" directly looking for "null"
|
|
438
|
+
// option but we don't have direct access at this point.
|
|
439
|
+
// Otherwise the JSON Schema validator will fail as explained in PR#18
|
|
432
440
|
field.jsonType.includes("null");
|
|
433
441
|
if (isOptionalWithNull) {
|
|
434
442
|
return [...optionsBroken, null];
|
|
435
443
|
}
|
|
436
|
-
return
|
|
444
|
+
return [
|
|
445
|
+
...optionsBroken,
|
|
446
|
+
null
|
|
447
|
+
// [3]
|
|
448
|
+
];
|
|
437
449
|
};
|
|
438
450
|
var getYupSchema = ({ inputType, ...field }) => {
|
|
439
451
|
const jsonType = getJsonTypeInArray(field.jsonType);
|
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.4.1-dev.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.4.1-dev.20230703161935
|
|
5
|
+
Generated: Mon, 03 Jul 2023 16:19:50 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -386,18 +386,30 @@ function getRequiredErrorMessage(inputType, { inlineError, configError }) {
|
|
|
386
386
|
var getJsonTypeInArray = (jsonType) => Array.isArray(jsonType) ? jsonType.find((val) => val !== "null") : jsonType;
|
|
387
387
|
var getOptionsAllowed = (field) => {
|
|
388
388
|
const onlyValues = field.options?.map((option) => option.value);
|
|
389
|
-
const optionsBroken = [
|
|
389
|
+
const optionsBroken = [
|
|
390
|
+
...onlyValues,
|
|
391
|
+
""
|
|
392
|
+
// [1]
|
|
393
|
+
];
|
|
390
394
|
if (field.required) {
|
|
391
|
-
return
|
|
395
|
+
return [
|
|
396
|
+
...optionsBroken,
|
|
397
|
+
null
|
|
398
|
+
// [2]
|
|
399
|
+
];
|
|
392
400
|
}
|
|
393
|
-
const isOptionalWithNull = Array.isArray(field.jsonType) && // @TODO should also check the "oneOf" directly looking for "null"
|
|
394
|
-
// but we don't have direct access at this point.
|
|
395
|
-
// the JSON Schema validator will fail
|
|
401
|
+
const isOptionalWithNull = Array.isArray(field.jsonType) && // @TODO should also check the "oneOf" directly looking for "null"
|
|
402
|
+
// option but we don't have direct access at this point.
|
|
403
|
+
// Otherwise the JSON Schema validator will fail as explained in PR#18
|
|
396
404
|
field.jsonType.includes("null");
|
|
397
405
|
if (isOptionalWithNull) {
|
|
398
406
|
return [...optionsBroken, null];
|
|
399
407
|
}
|
|
400
|
-
return
|
|
408
|
+
return [
|
|
409
|
+
...optionsBroken,
|
|
410
|
+
null
|
|
411
|
+
// [3]
|
|
412
|
+
];
|
|
401
413
|
};
|
|
402
414
|
var getYupSchema = ({ inputType, ...field }) => {
|
|
403
415
|
const jsonType = getJsonTypeInArray(field.jsonType);
|
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.4.1-dev.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.4.1-dev.20230703161935
|
|
5
|
+
Generated: Mon, 03 Jul 2023 16:19:50 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -11362,18 +11362,30 @@ function getRequiredErrorMessage(inputType, { inlineError, configError }) {
|
|
|
11362
11362
|
var getJsonTypeInArray = (jsonType) => Array.isArray(jsonType) ? jsonType.find((val) => val !== "null") : jsonType;
|
|
11363
11363
|
var getOptionsAllowed = (field) => {
|
|
11364
11364
|
const onlyValues = field.options?.map((option) => option.value);
|
|
11365
|
-
const optionsBroken = [
|
|
11365
|
+
const optionsBroken = [
|
|
11366
|
+
...onlyValues,
|
|
11367
|
+
""
|
|
11368
|
+
// [1]
|
|
11369
|
+
];
|
|
11366
11370
|
if (field.required) {
|
|
11367
|
-
return
|
|
11371
|
+
return [
|
|
11372
|
+
...optionsBroken,
|
|
11373
|
+
null
|
|
11374
|
+
// [2]
|
|
11375
|
+
];
|
|
11368
11376
|
}
|
|
11369
|
-
const isOptionalWithNull = Array.isArray(field.jsonType) && // @TODO should also check the "oneOf" directly looking for "null"
|
|
11370
|
-
// but we don't have direct access at this point.
|
|
11371
|
-
// the JSON Schema validator will fail
|
|
11377
|
+
const isOptionalWithNull = Array.isArray(field.jsonType) && // @TODO should also check the "oneOf" directly looking for "null"
|
|
11378
|
+
// option but we don't have direct access at this point.
|
|
11379
|
+
// Otherwise the JSON Schema validator will fail as explained in PR#18
|
|
11372
11380
|
field.jsonType.includes("null");
|
|
11373
11381
|
if (isOptionalWithNull) {
|
|
11374
11382
|
return [...optionsBroken, null];
|
|
11375
11383
|
}
|
|
11376
|
-
return
|
|
11384
|
+
return [
|
|
11385
|
+
...optionsBroken,
|
|
11386
|
+
null
|
|
11387
|
+
// [3]
|
|
11388
|
+
];
|
|
11377
11389
|
};
|
|
11378
11390
|
var getYupSchema = ({ inputType, ...field }) => {
|
|
11379
11391
|
const jsonType = getJsonTypeInArray(field.jsonType);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remoteoss/json-schema-form",
|
|
3
|
-
"version": "0.4.1-dev.
|
|
3
|
+
"version": "0.4.1-dev.20230703161935",
|
|
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",
|
|
@@ -461,11 +461,14 @@ describe('createHeadlessForm', () => {
|
|
|
461
461
|
});
|
|
462
462
|
|
|
463
463
|
// As required field, empty string ("") is also considered empty. @BUG RMT-518
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
464
|
+
// Expectation: The error to be "The option '' is not valid."
|
|
465
|
+
expect(validateForm({ [fieldName]: '' })).toEqual({
|
|
466
|
+
[fieldName]: 'Required field',
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
// As required field, null is also considered empty @BUG RMT-518
|
|
470
|
+
// Expectation: The error to be "The option null is not valid."
|
|
471
|
+
expect(validateForm({ [fieldName]: null })).toEqual({
|
|
469
472
|
[fieldName]: 'Required field',
|
|
470
473
|
});
|
|
471
474
|
}
|
|
@@ -849,26 +852,31 @@ describe('createHeadlessForm', () => {
|
|
|
849
852
|
expect(validateForm({ has_car: '' })).toBeUndefined();
|
|
850
853
|
}
|
|
851
854
|
|
|
852
|
-
it('
|
|
853
|
-
const { handleValidation } = createHeadlessForm(
|
|
855
|
+
it('normal optional (conventional way)', () => {
|
|
856
|
+
const { handleValidation } = createHeadlessForm(schemaInputRadioOptionalConventional);
|
|
854
857
|
const validateForm = (vals) => friendlyError(handleValidation(vals));
|
|
855
858
|
|
|
856
859
|
assertCommonBehavior(validateForm);
|
|
857
860
|
|
|
858
|
-
// Accepts null
|
|
861
|
+
// Accepts null, even though it shoudln't @BUG RMT-518
|
|
862
|
+
// This is for cases where we (Remote) still have incorrect
|
|
863
|
+
// JSON Schemas in our Platform.
|
|
859
864
|
expect(validateForm({ has_car: null })).toBeUndefined();
|
|
865
|
+
// Expected:
|
|
866
|
+
// // Does NOT accept null value
|
|
867
|
+
// expect(validateForm({ has_car: null })).toEqual({
|
|
868
|
+
// has_car: 'The option null is not valid.',
|
|
869
|
+
// });
|
|
860
870
|
});
|
|
861
871
|
|
|
862
|
-
it('
|
|
863
|
-
const { handleValidation } = createHeadlessForm(
|
|
872
|
+
it('with null option (as Remote does)', () => {
|
|
873
|
+
const { handleValidation } = createHeadlessForm(schemaInputRadioOptionalNull);
|
|
864
874
|
const validateForm = (vals) => friendlyError(handleValidation(vals));
|
|
865
875
|
|
|
866
876
|
assertCommonBehavior(validateForm);
|
|
867
877
|
|
|
868
|
-
//
|
|
869
|
-
expect(validateForm({ has_car: null })).
|
|
870
|
-
has_car: 'The option null is not valid.',
|
|
871
|
-
});
|
|
878
|
+
// Accepts null value
|
|
879
|
+
expect(validateForm({ has_car: null })).toBeUndefined();
|
|
872
880
|
});
|
|
873
881
|
});
|
|
874
882
|
|
|
@@ -200,7 +200,7 @@ export const schemaInputTypeHidden = {
|
|
|
200
200
|
...mockSelectInputSolo,
|
|
201
201
|
title: 'Select hidden',
|
|
202
202
|
'x-jsf-presentation': { inputType: 'hidden' },
|
|
203
|
-
default: '
|
|
203
|
+
default: 'chr',
|
|
204
204
|
},
|
|
205
205
|
a_hidden_select_multiple: {
|
|
206
206
|
...schemaInputTypeCountriesMultiple.properties.nationality,
|
package/src/tests/helpers.js
CHANGED
|
@@ -1696,7 +1696,7 @@ export const schemaWithConditionalToFieldset = {
|
|
|
1696
1696
|
properties: {
|
|
1697
1697
|
work_hours_per_week: {
|
|
1698
1698
|
title: 'Hours per week',
|
|
1699
|
-
type: '
|
|
1699
|
+
type: 'number',
|
|
1700
1700
|
description: 'Above 30 hours, the Perk>Food options change, and PTO is required.',
|
|
1701
1701
|
'x-jsf-presentation': {
|
|
1702
1702
|
inputType: 'number',
|
|
@@ -1704,7 +1704,7 @@ export const schemaWithConditionalToFieldset = {
|
|
|
1704
1704
|
},
|
|
1705
1705
|
pto: {
|
|
1706
1706
|
title: 'Time-off (days)',
|
|
1707
|
-
type: '
|
|
1707
|
+
type: 'number',
|
|
1708
1708
|
'x-jsf-presentation': {
|
|
1709
1709
|
inputType: 'number',
|
|
1710
1710
|
},
|