question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validation messages

See original GitHub issue

Is 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:open
  • Created 8 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pgomcommented, Oct 24, 2018

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.

0reactions
guillaumepotiercommented, Oct 24, 2018

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 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found