Validate groups of fields
By passing group validations.
Group validations utilize the groupValidation
prop on <OneForm />
. It's not often you'll need to validate groups of fields, but when you do, OneForm provides a powerful API.
Validate field groups
An array of objects containing a getErrorMessages
function that gets called when any subscribed value changes.
When returning a value, instead of returning a boolean, you need to specify which fields actually errored and the message for each of those fields. In the above example, we returned an error message on only the lastName
field.
Change vs Submit validation
Using the validationType
prop (passed into your getErrorMessages
function), it's possible to perform a different validation on field changes versus form submission.
A good example is when you might not want to show an error message about a date being incorrect until the form is submitted, when it really matters.
Avoiding namespace conflicts
To avoid namespace conflicts, prefix your field names with the component name:
This is only recommended if you're packaging fields in separate components as it shouldn't matter otherwise.
If you're wondering how you can render loops of components that share the same names, now you're looking for <FieldGroup />
, and this is all bundled into dynamic field validation.
Last updated