Skip to content

Commit 3f1146d

Browse files
committed
Fix dataType validators in get validates
1 parent 3e36644 commit 3f1146d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/react-form-renderer/src/get-validates/get-validates.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import get from 'lodash/get';
22

33
import prepareComponentProps from '../prepare-component-props';
4+
import { dataTypeValidator } from '../validators/validator-functions';
45

56
const getValidates = (schema, { componentMapper, actionMapper, values }, validations = {}) => {
67
if (Array.isArray(schema)) {
@@ -31,6 +32,10 @@ const getValidates = (schema, { componentMapper, actionMapper, values }, validat
3132

3233
validate = validate || overrideProps.validate || componentProps.validate;
3334

35+
if (schema.dataType) {
36+
validate = [...(validate || []), dataTypeValidator(schema.dataType)()];
37+
}
38+
3439
if (validate) {
3540
if (validations[schema.name]) {
3641
validations[schema.name].push(validate);

packages/react-form-renderer/src/tests/validation/get-validates.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ describe('getValidates', () => {
5151
name: 'xx',
5252
component: 'componentDefault',
5353
resolveProps: (_props, _inputMeta, { getState }) => ({ validate: [{ type: getState().values['x'] }] })
54-
}
54+
},
55+
{ name: 'datatype-validation', component: 'default', dataType: 'number' }
5556
]
5657
};
5758

@@ -77,7 +78,8 @@ describe('getValidates', () => {
7778
'simple-resolve': [[{ type: 'from-resolve-props' }]],
7879
'component-actions-resolve': [[{ type: 'actions>resolveProps' }]],
7980
x: [[{ type: 'value-of-x' }]],
80-
xx: [[{ type: 'value-of-x' }]]
81+
xx: [[{ type: 'value-of-x' }]],
82+
'datatype-validation': [[expect.any(Function)]]
8183
});
8284
});
8385
});

0 commit comments

Comments
 (0)