Skip to content

Commit 2725a29

Browse files
committed
fix(renderer): Allow undefined value for validate attribute in schema.
1 parent 2a17dc5 commit 2725a29

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

packages/pf3-component-mapper/demo/demo-schemas/sandbox.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const output = {
4242
bsSize: 'mn',
4343
onText: 'True',
4444
offText: 'False',
45+
validate: undefined,
4546
},
4647
{
4748
name: 'text_box_111',

packages/react-form-renderer/src/parsers/default-schema-validator.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ const checkCondition = (condition, fieldName) => {
6060
};
6161

6262
const checkValidators = (validate, fieldName) => {
63+
if (validate === undefined) {
64+
return;
65+
}
66+
6367
if (!Array.isArray(validate)) {
6468
throw new DefaultSchemaError(`
6569
Error occured in field definition with name: "${fieldName}".

packages/react-form-renderer/src/tests/parsers/default-schema-validator.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ describe('Default schema validator', () => {
104104
}]}, formFieldsMapper)).toThrowErrorMatchingSnapshot();
105105
});
106106

107+
it('should not fail if validate is undefined.', () => {
108+
expect(() => defaultSchemaValidator({ fields: [{
109+
component: 'foo',
110+
name: 'foo',
111+
validate: undefined,
112+
}]}, formFieldsMapper)).not.toThrow();
113+
});
114+
107115
it('should not fail if field validate item is a function.', () => {
108116
const functionValidator = (value) => 'cosi';
109117
expect(() => defaultSchemaValidator({ fields: [{

0 commit comments

Comments
 (0)