@@ -352,8 +352,9 @@ export default class EccUtilsDesignForm extends LitElement {
352352 const { value } = e . target as HTMLInputElement ;
353353 if ( ! value ) {
354354 _ . unset ( this . form , path ) ;
355+ if ( field . fieldOptions ?. returnIfEmpty ) _ . set ( this . form , path , null ) ;
355356 } else {
356- _ . set ( this . form , path , value ) ;
357+ _ . set ( this . form , path , value . trim ( ) ) ;
357358 }
358359 this . requestUpdate ( ) ;
359360 this . alertFieldChange ( field . key , value ) ;
@@ -548,9 +549,24 @@ export default class EccUtilsDesignForm extends LitElement {
548549 return this . renderArrayTemplate ( field , newPath ) ;
549550 }
550551
551- if ( field . fieldOptions ?. required && ! _ . get ( this . form , newPath ) ) {
552- this . requiredButEmpty . push ( field . key ) ;
552+ if ( field . fieldOptions ?. required ) {
553+ if (
554+ ! _ . get ( this . form , newPath ) &&
555+ ! this . requiredButEmpty . includes ( field . key )
556+ ) {
557+ // add to requiredButEmpty
558+
559+ // eslint-disable-next-line no-empty
560+ if ( ! this . hasUpdated && field . fieldOptions . default ) {
561+ } else this . requiredButEmpty . push ( field . key ) ;
562+ } else if ( _ . get ( this . form , newPath ) ) {
563+ // remove from requiredButEmpty
564+ this . requiredButEmpty = this . requiredButEmpty . filter (
565+ ( key ) => key !== field . key
566+ ) ;
567+ }
553568 }
569+
554570 if ( field . type === "switch" ) {
555571 return this . renderSwitchTemplate ( field , newPath ) ;
556572 }
@@ -648,7 +664,6 @@ export default class EccUtilsDesignForm extends LitElement {
648664 }
649665
650666 render ( ) {
651- this . requiredButEmpty = [ ] ;
652667 if ( ! this . fields || this . fields . length === 0 ) {
653668 throw new Error ( "Fields is required & should not be empty array" ) ;
654669 }
0 commit comments