gerhat / material-ui-formik-components

Formik ready material ui components
MIT License
85 stars 13 forks source link

Error message not shown if submit is clicked before touching any of the fields. Yup validation. #41

Closed pzapo closed 3 years ago

pzapo commented 3 years ago

I have form with two fields and both of them are required, when user clicks submit before entering any data no error is shown and nothing happens. Form return corrects errors in "error" object but nothing is displayed in UI.

Can I somehow force errors messages on not touched and empty form?

pzapo commented 3 years ago

I 've found solution using dirty but it is not enough. I am able to disable submit untill one of the fields is touched but then situation happens again. Second field doesn't show required error.

gerhat commented 3 years ago

Errors are show when ALL the following conditions are met:

  1. form is dirty
  2. field is touched
  3. field has error

This is done intentionally to avoid the noise of showing errors in every field when the user hasn't even touched them. In my projects, I am usually disabling the submit button when the form is not valid.

I am open for discussion about the correct behaviour on this issue though. What do you think?

pzapo commented 3 years ago

I agree with you, I've followed your path with disabling the button.