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";
55
66export type ValidatorFunction = ( value : any , allValues : object ) => ReactNode | undefined ;
77
8+ export type convertToWarning = ( validator : ValidatorType ) => ValidatorFunction ;
9+
810export function prepareValidator (
911 validator : ValidatorFunction | ValidatorType ,
1012 mapper : ValidatorMapper ) : ValidatorFunction ;
Original file line number Diff line number Diff line change @@ -2,8 +2,22 @@ import { memoize } from '../validators/helpers';
22import { dataTypeValidator } from '../validators' ;
33import composeValidators from '../files/compose-validators' ;
44
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+ } ;
721
822export const getValidate = ( validate , dataType , mapper = { } ) => [
923 ...( validate ? validate . map ( ( validator ) => prepareValidator ( validator , mapper ) ) : [ ] ) ,
You can’t perform that action at this time.
0 commit comments