Reset and replace error messages
This typically happens when receiving error messages from an API request.
By passing an errorMessages
object to OneForm, you can reset all error messages and replace them with your own:
The HTML output looks like:
Merge or update error messages
Instead of resetting and replacing error messages, you may want to update them instead.
Use updatedErrorMessages
:
Custom error messages component
FormErrorMessage
only shows a single error. If you want to show all error messages, the useFieldErrorMessages
hook gives you the ability to write your own component.
You can output multiple field error messages like so:
When is this useful?
If you have an external API which returns error messages when someone fails to write to the database, this is the perfect example of when you'd want to wipe all form errors.
Another instance would be if you have no client-side validation and want to do everything server-side. At that point, it makes sense to always wipe OneForm's errors with whatever errorMessages
object you've passed in.
Last updated