@@ -4,6 +4,7 @@ import isNil from 'lodash/isNil';
44import isObject from 'lodash/isObject' ;
55import isObjectLike from 'lodash/isObjectLike' ;
66import isString from 'lodash/isString' ;
7+ import isEmpty from 'lodash/isEmpty' ;
78
89import {
910 FormValue ,
@@ -63,6 +64,7 @@ export const isNotEmptyValue = (value: FormValue | undefined, spec: Spec | undef
6364export const prepareSpec = < Type extends Spec > (
6465 spec : Type ,
6566 parseJsonDefaultValue ?: boolean ,
67+ overridePatternError ?: ( pattern ?: string ) => string ,
6668) : Type => {
6769 if ( isObjectLike ( spec ) ) {
6870 const result : Record < string , any > = cloneDeep ( spec ) ;
@@ -140,8 +142,12 @@ export const prepareSpec = <Type extends Spec>(
140142 }
141143 }
142144
145+ if ( ! isEmpty ( result . pattern ) && isEmpty ( result . patternError ) && overridePatternError ) {
146+ result . patternError = overridePatternError ( result . pattern ) ;
147+ }
148+
143149 if ( result . items ) {
144- result . items = prepareSpec ( result . items , parseJsonDefaultValue ) ;
150+ result . items = prepareSpec ( result . items , parseJsonDefaultValue , overridePatternError ) ;
145151 }
146152
147153 if ( result . maximum === 0 && result . minimum === 0 ) {
@@ -163,7 +169,11 @@ export const prepareSpec = <Type extends Spec>(
163169
164170 if ( isObjectLike ( result . properties ) ) {
165171 Object . keys ( result . properties ) . forEach ( ( key ) => {
166- result . properties [ key ] = prepareSpec ( result . properties [ key ] , parseJsonDefaultValue ) ;
172+ result . properties [ key ] = prepareSpec (
173+ result . properties [ key ] ,
174+ parseJsonDefaultValue ,
175+ overridePatternError ,
176+ ) ;
167177 } ) ;
168178 }
169179
0 commit comments