File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
packages/react-form-renderer/src Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,14 @@ describe('New validators', () => {
2828 } ) ;
2929
3030 describe ( 'Length validator' , ( ) => {
31+ it ( 'should pass empty value' , ( ) => {
32+ expect ( validatorMapper ( validators . EXACT_LENGTH ) ( { threshold : 5 } ) ( '' ) ) . toBeUndefined ( ) ;
33+ } ) ;
34+
35+ it ( 'should pass undefined value' , ( ) => {
36+ expect ( validatorMapper ( validators . EXACT_LENGTH ) ( { threshold : 5 } ) ( undefined ) ) . toBeUndefined ( ) ;
37+ } ) ;
38+
3139 it ( 'should pass exact length of 5 characters validation' , ( ) => {
3240 expect ( validatorMapper ( validators . EXACT_LENGTH ) ( { threshold : 5 } ) ( '12345' ) ) . toBeUndefined ( ) ;
3341 } ) ;
Original file line number Diff line number Diff line change @@ -21,7 +21,11 @@ export const length = memoize(({
2121 equal = selectNum ( equal , is ) ;
2222 min = selectNum ( min , minimum ) ;
2323 max = selectNum ( max , maximum ) ;
24- return prepare ( ( value = [ ] ) => {
24+ return prepare ( ( value ) => {
25+ if ( ! value ) {
26+ return ;
27+ }
28+
2529 if ( equal !== null && value . length !== equal ) {
2630 const msg = prepareMsg ( message , 'wrongLength' , { count : equal } ) . defaultMessage ;
2731 return typeof msg === 'string' ? msg : msg ( equal ) ;
You can’t perform that action at this time.
0 commit comments