@@ -6,7 +6,7 @@ import { withFieldWillValidateEventEmitter } from './withFieldWillValidateEventE
66import { withFieldDidValidateEventEmitter } from './withFieldDidValidateEventEmitter' ;
77import { withFieldDidResetEventEmitter } from './withFieldDidResetEventEmitter' ;
88import { Field } from './Field' ;
9- import { IHTMLInput , InputElement , HTMLInput } from './InputElement' ;
9+ import { IHTMLInput , InputElement , HTMLInput , TextInput } from './InputElement' ;
1010import { FieldsStore } from './FieldsStore' ;
1111import { FieldFeedbackValidation } from './FieldFeedbackValidation' ;
1212import { flattenDeep } from './flattenDeep' ;
@@ -84,24 +84,33 @@ export class FormWithConstraints
8484 for ( let i = 0 ; i < inputs . length ; i ++ ) {
8585 const input = inputs [ i ] ;
8686 // eslint-disable-next-line no-await-in-loop
87- const field = await this . validateField ( forceValidateFields , new InputElement ( input ) ) ;
88- if ( field !== undefined ) {
89- field . element = input as HTMLInput ;
90- fields . push ( field ) ;
91- }
87+ const field = await this . validateField (
88+ forceValidateFields ,
89+ new InputElement ( input ) ,
90+ input as HTMLInput | TextInput
91+ ) ;
92+ if ( field !== undefined ) fields . push ( field ) ;
9293 }
9394
9495 return fields ;
9596 }
9697
97- private async validateField ( forceValidateFields : boolean , input : InputElement ) {
98+ private async validateField (
99+ forceValidateFields : boolean ,
100+ input : InputElement ,
101+
102+ // We need to pass the native input separately instead of it being a property of InputElement
103+ // otherwise react-form-with-constraints-native unit tests will crash
104+ nativeInput : HTMLInput | TextInput
105+ ) {
98106 const fieldName = input . name ;
99107 const field = this . fieldsStore . getField ( fieldName ) ;
100108
101109 if ( field === undefined ) {
102110 // Means the field (<input name="username">) does not have a FieldFeedbacks
103111 // so let's ignore this field
104112 } else if ( forceValidateFields || ! field . hasFeedbacks ( ) ) {
113+ field . element = nativeInput as HTMLInput | TextInput ;
105114 field . clearValidations ( ) ;
106115
107116 this . emitFieldWillValidateEvent ( fieldName ) ;
0 commit comments