File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
packages/react-form-renderer/src/form-renderer Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ import { DataType } from "../files/data-types";
5
5
6
6
export type ValidatorFunction = ( value : any , allValues : object ) => ReactNode | undefined ;
7
7
8
+ export type convertToWarning = ( validator : ValidatorType ) => ValidatorFunction ;
9
+
8
10
export function prepareValidator (
9
11
validator : ValidatorFunction | ValidatorType ,
10
12
mapper : ValidatorMapper ) : ValidatorFunction ;
Original file line number Diff line number Diff line change @@ -2,8 +2,22 @@ import { memoize } from '../validators/helpers';
2
2
import { dataTypeValidator } from '../validators' ;
3
3
import composeValidators from '../files/compose-validators' ;
4
4
5
- export const prepareValidator = ( validator , mapper ) =>
6
- typeof validator === 'function' ? memoize ( validator ) : mapper [ validator . type ] ( { ...validator } ) ;
5
+ export const convertToWarning = ( validator ) => ( ...args ) => ( {
6
+ type : 'warning' ,
7
+ error : validator ( ...args )
8
+ } ) ;
9
+
10
+ export const prepareValidator = ( validator , mapper ) => {
11
+ if ( typeof validator === 'function' ) {
12
+ return memoize ( validator ) ;
13
+ }
14
+
15
+ if ( validator . warning ) {
16
+ return convertToWarning ( mapper [ validator . type ] ( { ...validator } ) ) ;
17
+ }
18
+
19
+ return mapper [ validator . type ] ( { ...validator } ) ;
20
+ } ;
7
21
8
22
export const getValidate = ( validate , dataType , mapper = { } ) => [
9
23
...( validate ? validate . map ( ( validator ) => prepareValidator ( validator , mapper ) ) : [ ] ) ,
You can’t perform that action at this time.
0 commit comments