@@ -19,7 +19,7 @@ import {
19
19
NumberComponent ,
20
20
} from 'types' ;
21
21
22
- type NormalizeScope = DefaultValueScope & {
22
+ export type NormalizeScope = DefaultValueScope & {
23
23
normalize ?: {
24
24
[ path : string ] : any ;
25
25
} ;
@@ -371,45 +371,41 @@ export const normalizeProcessSync: ProcessorFnSync<NormalizeScope> = (context) =
371
371
type : component . type ,
372
372
normalized : false ,
373
373
} ;
374
- // First check for component-type-specific transformations
374
+ let newValue = value ;
375
375
if ( isAddressComponent ( component ) ) {
376
- set ( data , path , normalizeAddressComponentValue ( component , value ) ) ;
377
- scope . normalize [ path ] . normalized = true ;
376
+ newValue = normalizeAddressComponentValue ( component , value ) ;
378
377
} else if ( isDayComponent ( component ) ) {
379
- set ( data , path , normalizeDayComponentValue ( component , form , value ) ) ;
380
- scope . normalize [ path ] . normalized = true ;
378
+ newValue = normalizeDayComponentValue ( component , form , value ) ;
381
379
} else if ( isEmailComponent ( component ) ) {
382
- if ( value && typeof value === 'string' ) {
383
- set ( data , path , value . toLowerCase ( ) ) ;
384
- scope . normalize [ path ] . normalized = true ;
385
- }
380
+ newValue = value && isString ( value ) ? value . trim ( ) . toLowerCase ( ) : value ;
386
381
} else if ( isRadioComponent ( component ) ) {
387
- set ( data , path , normalizeRadioComponentValue ( value , component . dataType ) ) ;
388
- scope . normalize [ path ] . normalized = true ;
382
+ newValue = normalizeRadioComponentValue ( value , component . dataType ) ;
389
383
} else if ( isSelectComponent ( component ) ) {
390
- set ( data , path , normalizeSelectComponentValue ( component , value ) ) ;
391
- scope . normalize [ path ] . normalized = true ;
384
+ newValue = normalizeSelectComponentValue ( component , value ) ;
392
385
} else if ( isSelectBoxesComponent ( component ) ) {
393
- set ( data , path , normalizeSelectBoxesComponentValue ( value ) ) ;
394
- scope . normalize [ path ] . normalized = true ;
386
+ newValue = normalizeSelectBoxesComponentValue ( value ) ;
395
387
} else if ( isTagsComponent ( component ) ) {
396
- set ( data , path , normalizeTagsComponentValue ( component , value ) ) ;
397
- scope . normalize [ path ] . normalized = true ;
388
+ newValue = normalizeTagsComponentValue ( component , value ) ;
398
389
} else if ( isTextFieldComponent ( component ) ) {
399
- set ( data , path , normalizeTextFieldComponentValue ( component , defaultValues , value , path ) ) ;
400
- scope . normalize [ path ] . normalized = true ;
390
+ newValue = normalizeTextFieldComponentValue ( component , defaultValues , value , path ) ;
401
391
} else if ( isTimeComponent ( component ) ) {
402
- set ( data , path , normalizeTimeComponentValue ( component , value ) ) ;
403
- scope . normalize [ path ] . normalized = true ;
392
+ newValue = normalizeTimeComponentValue ( component , value ) ;
404
393
} else if ( isNumberComponent ( component ) ) {
405
- set ( data , path , normalizeNumberComponentValue ( component , value ) ) ;
406
- scope . normalize [ path ] . normalized = true ;
394
+ newValue = normalizeNumberComponentValue ( component , value ) ;
407
395
}
408
396
409
- // Next perform component-type-agnostic transformations (i.e. super())
410
397
if ( component . multiple && ! component . validate ?. required && ! Array . isArray ( value ) ) {
411
- set ( data , path , value ? [ value ] : [ ] ) ;
398
+ newValue = value ? [ value ] : [ ] ;
399
+ }
400
+
401
+ if ( newValue === undefined || newValue === null ) {
402
+ scope . filter = scope . filter || { } ;
403
+ scope . filter [ path ] = false ;
404
+ } else if ( value !== newValue && ! ( scope as any ) . clearHidden ?. hasOwnProperty ( path ) ) {
405
+ set ( data , path , newValue ) ;
412
406
scope . normalize [ path ] . normalized = true ;
407
+ scope . filter = scope . filter || { } ;
408
+ scope . filter [ path ] = true ;
413
409
}
414
410
} ;
415
411
0 commit comments