Validation messages
See original GitHub issueIs it possible to get error messages? When an object doesn’t pass validation I would like to get errors messages to display, for example:
var rules = {
name: [ new Validator.Assert().Length( { min: 10 } ) ],
email: [ new Validator.Assert().NotBlank() ],
lastname: [new Assert().IsString()]
};
var model = {
name: 'Mike',
lastname: 'Perez'
};
var constraint = new Constraint(rules)
constraint.check(model).messages
and get
{
name: ['Length should be greater than 10'],
email: ['This field is required']
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Error Messages: Examples, Best Practices & Common Mistakes
Useful error messages can keep users on your site and increase conversions. See examples and learn the best practices.
Read more >Validation messages - IBM
When you have validation enabled, you can receive messages that validate a filter or function expression. You can receive either warnings or errors...
Read more >How to Write Good Error Messages - UX Planet
1. Be Clear And Not Ambiguous · 2. Be Short And Meaningful · 3. Don't Use Technical Jargons · 4. Be Humble —...
Read more >Best 10 Examples And Guidelines For Error Messages
Best 10 Examples And Guidelines For Error Messages · 1. Keep language clear and concise · 2. Keep user actions specific and logical...
Read more >Designing Better Error Messages UX - Smashing Magazine
Error messages need to be easy to spot, but they also need to be helpful. Let's explore when error messages should live above...
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 for getting back @guillaumepotier. I agree with you in not having the core have such a file but getting the possibility of defining a specific label by field (even if the constraint is the same) would make much sense for this. I’ll try to get around a solution on my own and when I feel it will be good enough, I’ll happily create a PR with it.
Hi @pgom
That’s right, it’s been some time I haven’t been here, and this topic went idle.
As of today, I’m still convinced that this should be an external new object/method maybe in a different optional file (to avoid shipping it systematically with main validatorjs core) (like discussed above) and we should use default english string file like in Parsley (with sprintf equiv to replace min/max placeholder values in the i18n strings).
These messages of course should be replaced globally AND specifically (eg: field by field, to replace “This value should not be blank” by “You must enter your name”)
I’d be glad to assist you in a PR as a reviewer, but not much more as my time is currently very short 😃