Show only one error message
See original GitHub issueFor my field validation, I have
yup.string()
.matches(
/^[A-Z]/,
{
message: 'Name must start with a capital letter',
excludeEmptyString: true,
},
)
.matches(
/^.[a-zA-Z0-9_]+$/,
{
message: 'Alphanumeric characters or underscores only',
excludeEmptyString: true,
},
)
.required('Name is requried.'),
Sometimes, both errors from the matches()
, will show. This makes sense since both errors triggered. However, the way it’s displayed can be a bit messy:
Name must start with a capital letter., Alphanumeric characters or underscores only.
Is there any way to only show one message at a time? Or possibly replace the comma with a period?
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Displaying only one error message per field - Stack Overflow
Inspired by new validation methods in Rails 3.0 I'm adding this tiny Validator. I call it ReduceValidator . lib/reduce_validator.rb : # show ......
Read more >Display all validation rule errors at once - IdeaExchange
If you click on the Edit button and trigger more than one validation rule, all the messages appear. If I inline edit, only...
Read more >Displaying Errors - VeeValidate
Typically you would want to display one error at a time for your fields, you can do this using errors.first('fieldName') method. ... VeeValidate...
Read more >Showing only one message each time - FormValidation
This event is triggered when the field doesn't pass a particular validator. In the following registration form, the username field must pass three...
Read more >UX Design: Four ways to display error messages - Nomensa
One example of an unclear error message is on the Hotmail registration ... Before the year 2000, it was common to use only...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @jquense, I think this will work (grabbing first error field and using as error):
@jquense Understood. I just double checked and it appears that changing the order of the chained
name
validation methods will change the order in which the errors appear. For instance, switching toYup.string().required().min()
will display therequired
message before themin
messages, whereasYup.string().min().required()
will display it afterward.Or is this just a lucky coincidence because the first one just happaned to start before the other? Also, if
validateSync
is synchronous, do the validations still run in parallel?