flipbyte / formik-json-schema

Easily create react forms using JSON / Javascript Object
MIT License
151 stars 40 forks source link

Show error message when any field is invalid #68

Closed andrewringler closed 4 years ago

andrewringler commented 4 years ago

I have a bunch of fields with field-level validation. When I click submit on the form, I get error messages inline with each invalid field but I would also like to display an error message near the submit button that says something like "Please correct the highlighted fields above".

Is there any way to access to the state of form validation from the

component? And/or is there any way to configure a form level validation message in the JSON?

easeq commented 4 years ago

Form level validation is not available out-of-the box, but you can use a custom container or a custom submit button field and add your validation check there.

Each custom element (container or field) gets an object formik which holds the formik props. You can use it to check your logic and show a message based on that logic.

andrewringler commented 4 years ago

Thanks, that makes sense. Andrew