NewOldMax / react-form-validator-core

Core validator component for react forms
MIT License
95 stars 44 forks source link

instantValidate function not being called #33

Closed smoosh911 closed 6 years ago

smoosh911 commented 6 years ago

Using should prevent instant validation. It looks like in the ValidatorComponent.jsx you guys are checking if the this.instantValidate exists rather than calling it.

Current Code: componentDidUpdate(prevProps, prevState) { if (**this.instantValidate** && this.props.value !== prevState.value) { this.validateDebounced(this.props.value, this.props.withRequiredValidator); } }

Suggested Fix: componentDidUpdate(prevProps, prevState) { if (**this.instantValidate()** && this.props.value !== prevState.value) { this.validateDebounced(this.props.value, this.props.withRequiredValidator); } }

NewOldMax commented 6 years ago

Hi instantValidate is not a function, it's boolean value

smoosh911 commented 6 years ago

@NewOldMax go through the debugger. You will see that by the time it gets to the if statement I've mentioned, it is referencing the function that is pulled from the form validator. It looks like you guys are setting a boolean here but then that overrides the functions you are calling from the form validator, so then why have those? If you are just using the boolean then the function reference to form validator is pointless and you might as well remove that function.

NewOldMax commented 6 years ago

All ValidatorComponent's take global instantValidate value from ValidatorForm only once and later reuse it. And it's a boolean value, not a function, so no reference here, just taking value from context

CarmitK commented 5 years ago

Hi, I would like to give instantValidate a dynamic value: at init make it 'false' (with validations on blur), and after trying to submit make it 'true'.

NewOldMax commented 5 years ago

@CarmitK you can try to change it manually via ref

this.form.instantValidate = false;
this.form.instantValidate = true;

<ValidatorForm ref={r => (this.form = r}>