New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validatorName to the list of error messages #14

Closed
mattruby opened this Issue Dec 17, 2014 · 3 comments

Comments

Projects
None yet
3 participants
@mattruby
Copy link

mattruby commented Dec 17, 2014

It would be nice to be able to style error messages based on the validation type. Perhaps the return type could be set as on option.

Today:
{password: ["Password can't be blank"]}

Suggestion:
{password: [{validatorName:"length", errorMessage: "Password is too short (minimum is 6 characters)", value: "pass"}]}

The catalyst for wanting this change is a warning state where I suggest an email correction: "Did you mean comcast.net in place of comcast.com". This message would be interactive with a link to the corrected address.

@ansman

This comment has been minimized.

Copy link
Owner

ansman commented Dec 20, 2014

That sounds like a good idea.

I'm on vacation right now but I'll look in to this when I get back in January.

On Thu, Dec 18, 2014 at 7:48 AM, mattruby notifications@github.com
wrote:

It would be nice to be able to style error messages based on the validation type. Perhaps the return type could be set as on option.
Today:
{password: ["Password can't be blank"]}
Suggestion:
{password: [{validatorName:"length", errorMessage: "Password is too short (minimum is 6 characters)", value: "pass"}]}

The catalyst for wanting this change is a warning state where I suggest an email correction: "Did you mean comcast.net in place of comcast.com". This message would be interactive with a link to the corrected address.

Reply to this email directly or view it on GitHub:
#14

@tamtakoe

This comment has been minimized.

Copy link

tamtakoe commented Dec 26, 2014

phoneNumber: [{
    required: true;
    message:  'isEmpty'
}, {
    pattern: '[0-9]+',
    message: 'notInt'
}, {
    length:  11,
    message: 'invalidLength'
}, {
    unique:  'phoneNumber',
    model:   User,
    message: 'exists'
}]

@ansman ansman added this to the Next milestone Apr 3, 2015

@ansman ansman added the enhancement label Apr 3, 2015

@ansman ansman closed this in fc2e722 Apr 8, 2015

@ansman

This comment has been minimized.

Copy link
Owner

ansman commented Apr 8, 2015

Released in 0.7.0

You can now to the following:

var constraints = {
  username: {
    presence: true
  }
};
validate({}, constraints, {format: "detailed"});
// => [{
//   "attribute": "username",
//   "validator": "presence",
//   "options": true,
//   "error": "Username can't be blank"
// }]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment