One of the more complex form inputs we have is our email input.
There are specifically two features that stand out, that I’d use as a litmus test for any validation framework.
It sends the email, as it’s typed, to the backend for validation/verification against blacklists. So it’s async. It also doesn’t start sending the email to the backend until it’s a valid email according to very basic front-end rules (needs to include @ and .tld basically), or until the user tries to submit the form. After any of those have happened it continuously sends to the backend (debounced).
It looks at the email and suggests corrections for basic typos “name@gmil.com” → “Did you mean name@gmail.com?” where the suggestion is clickable to change the form input to that value instead. It’s just a suggestion (shown in yellow instad of red) and won’t prevent submitting the form, and is also dismissible by clicking on a “x”.
Any validation framework should support, or at least not be in the way of implementing, those two features.
You can also write your own scalars for validation – something I’ll write up as I am currently writing one to rework the roles support in Redwood so you can di something like:
type Query {
randomMovie: Movie! @requireAuth(roles: ["player", "visitor"]) // <-- an array of strings
createGame: Game! @requireAuth(roles: "admin") // <-- a string
}
A custom scalar here allows a string or an array of strings.
While this is used in a directive, the same principles apply to an Input or even the result data.