Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Built-in form validation / web native form validation #127

Open
coryhouse opened this issue May 4, 2022 · 0 comments
Open

Built-in form validation / web native form validation #127

coryhouse opened this issue May 4, 2022 · 0 comments

Comments

@coryhouse
Copy link
Owner

coryhouse commented May 4, 2022

Overview

My take on why it should be avoided

Note: You can set novalidate to disable native validation and display your own custom validation messages by checking the status of the validity of each field. However, that only addresses my first point on the tweet above.

Other reasons to avoid, mentioned in the thread above:

  1. It's not accessible
  2. Doesn't support async validation
  3. Doesn't support validation based on the values of other fields in your forum

Three key pieces to built-in form validation:

  1. Use HTML validation attributes to enforce required fields
  2. Use the FormData API to read values out of the form rather than track their values in state.
  3. Optionally, customize error messages using the Constraint Validation API and the ElementInternals API (which isn't supported in Safari yet)

The tradeoff: Built-in validation isn't as customizable as JS validation. And, it looks different across browser, which cannot be resolved.

@coryhouse coryhouse changed the title Web native forms Built-in form validation / web native form validation May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant