Skip to content

How to get form validity without submitting it or triggering field errors #713

Answered by marcomuser
ETombuyses asked this question in Q&A
Discussion options

You must be logged in to vote

Usually, I would propose to not disable the submit button at all but trigger the form validation and focus the first field with an error on submit. This is what browsers do by default. There are some UX pitfalls with disabled submit buttons to think about, see https://www.smashingmagazine.com/2021/08/frustrating-design-patterns-disabled-buttons/. If that would be acceptable to your requirements your problem would just disappear all-together. If that doesn't fulfill your specific requirements, you could look into using parseWithZod with current form.value converted to a FormData object. This would allow you to validate the validity of your form independent of the onValidate handler and thu…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@marcomuser
Comment options

@ETombuyses
Comment options

@marcomuser
Comment options

Answer selected by ETombuyses
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants