Question - trigger validation on submit
IrvingArmenta opened this issue · 1 comments
Is there a way to trigger validation for all inputs on "Submit" ? something like formState.validateFields()
or something.
I don't want to use the HTML5
api for form validation at all (<form noValidate={true} />
) , therefore when the user clicks "submit" I want the fields that are required
to show the error message that they're required. This is how react-hook-form
and other frameworks work.
I understand I can "disable" the submit button with the Pristine()
function, but I don't want to disable this button, also, if there is a field input that needs to have the same value as other input (password confirmation or email confirmation) the user can just click "submit" either way, since Pristine()
just throws false
at this point.
Is there a work around for this functionality?
A possible workaround would be to validate each field by inspecting formState.values
.
For each invalid field, you could call formState.setFieldError
.
Although this requires a bit of extra code, I think this would get you your desired result.