@@ -59,6 +59,8 @@ export default class Field extends Base {
5959
6060 @observable $submitting = false ;
6161 @observable $validating = false ;
62+ @observable $clearing = false ;
63+ @observable $resetting = false ;
6264
6365 @observable autoFocus = false ;
6466 @observable showError = false ;
@@ -145,6 +147,10 @@ export default class Field extends Base {
145147 this . $default = parseFieldValue ( this . $parser , { separated : val } ) ;
146148 }
147149
150+ @computed get actionRunning ( ) {
151+ return ( this . submitting || this . clearing || this . resetting ) ;
152+ }
153+
148154 @computed get submitting ( ) {
149155 return toJS ( this . $submitting ) ;
150156 }
@@ -222,6 +228,18 @@ export default class Field extends Base {
222228 : _ . isEqual ( this . $default , this . value ) ;
223229 }
224230
231+ @computed get resetting ( ) {
232+ return this . hasNestedFields
233+ ? this . check ( 'resetting' , true )
234+ : this . $resetting ;
235+ }
236+
237+ @computed get clearing ( ) {
238+ return this . hasNestedFields
239+ ? this . check ( 'clearing' , true )
240+ : this . $clearing ;
241+ }
242+
225243 @computed get isEmpty ( ) {
226244 if ( this . hasNestedFields ) return this . check ( 'isEmpty' , true ) ;
227245 if ( _ . isBoolean ( this . value ) ) return ! ! this . $value ;
@@ -519,15 +537,19 @@ export const prototypes = {
519537
520538 @action
521539 clear ( deep = true , call = true ) {
540+ this . $clearing = true ;
522541 this . $touched = false ;
523542 this . $changed = false ;
524543
525544 this . $value = defaultClearValue ( { value : this . $value } ) ;
526545 this . files = undefined ;
527546
528- this . showErrors ( this . state . options . get ( 'showErrorsOnClear' , this ) ) ;
529547 if ( deep ) this . each ( field => field . clear ( true , false ) ) ;
530548
549+ this . validate ( {
550+ showErrors : this . state . options . get ( 'showErrorsOnClear' , this ) ,
551+ } ) ;
552+
531553 if ( call ) {
532554 this . $onClear . apply ( this , [ {
533555 form : this . state . form ,
@@ -538,6 +560,7 @@ export const prototypes = {
538560
539561 @action
540562 reset ( deep = true , call = true ) {
563+ this . $resetting = true ;
541564 this . $touched = false ;
542565 this . $changed = false ;
543566
@@ -546,9 +569,12 @@ export const prototypes = {
546569 if ( ! useDefaultValue ) this . value = this . $initial ;
547570 this . files = undefined ;
548571
549- this . showErrors ( this . state . options . get ( 'showErrorsOnReset' , this ) ) ;
550572 if ( deep ) this . each ( field => field . reset ( true , false ) ) ;
551573
574+ this . validate ( {
575+ showErrors : this . state . options . get ( 'showErrorsOnReset' , this ) ,
576+ } ) ;
577+
552578 if ( call ) {
553579 this . $onReset . apply ( this , [ {
554580 form : this . state . form ,
@@ -581,19 +607,22 @@ export const prototypes = {
581607 } ,
582608
583609 observeValidation ( type ) {
584- const validateOnChange = this . state . options . get ( 'validateOnChange' , this ) ;
585- const showErrorsOnChange = this . state . options . get ( 'showErrorsOnChange' , this ) ;
586- const validateOnBlur = this . state . options . get ( 'validateOnBlur' , this ) ;
587- const showErrorsOnBlur = this . state . options . get ( 'showErrorsOnBlur ', this ) ;
588-
589- if ( type === 'onBlur' || ( validateOnBlur ) ) {
590- this . disposeValidationOnBlur = observe ( this , '$focused ', ( { newValue } ) =>
591- ( newValue === false ) && this . debouncedValidation ( { showErrors : showErrorsOnBlur } ) ) ;
610+ const opt = this . state . options ;
611+
612+ if ( type === 'onBlur' || opt . get ( 'validateOnBlur' , this ) ) {
613+ observe ( this , '$focused ', ( { newValue } ) =>
614+ ( newValue === false ) &&
615+ this . debouncedValidation ( {
616+ showErrors : opt . get ( 'showErrorsOnBlur ', this ) ,
617+ } ) ) ;
592618 }
593619
594- if ( type === 'onChange' || validateOnChange ) {
620+ if ( type === 'onChange' || opt . get ( ' validateOnChange' , this ) ) {
595621 this . disposeValidationOnChange = observe ( this , '$value' , ( ) =>
596- this . debouncedValidation ( { showErrors : showErrorsOnChange } ) ) ;
622+ ! this . actionRunning &&
623+ this . debouncedValidation ( {
624+ showErrors : opt . get ( 'showErrorsOnChange' , this ) ,
625+ } ) ) ;
597626 }
598627 } ,
599628
0 commit comments