willowtreeapps / react-formable

React Forms
25 stars 5 forks source link

onSubmit delay #101

Closed kaw2k closed 7 years ago

kaw2k commented 7 years ago

So it is debatable if onSubmit should be called with an invalid form. 90% of the time you can just have the default form validation take care of showing errors. In that case, it is just a distraction to call onSubmit with bad form data.

This PR adds a prop to change how this works. Setting this prop to false will cause the form not to call onSubmit with bad form data.

Thoughts on prop name / other thoughts?

samuelmaddock commented 7 years ago

I agree with your assessment and think it's more idiomatic to how HTML forms are implemented according to spec. By default forms won't submit unless the form is valid. The attribute name to bypass this behavior is novalidate in HTML.

kaw2k commented 7 years ago

I agree @samuelmaddock. I changed the default to not calling onSubmit if the form is invalid. If noValidate is present, onSubmit will be called regardless. In both situations, validation is passed to onSubmit.