resourcer
resourcer copied to clipboard
How do you specify custom error messages when validate() fails?
this.property('to', 'string', {
required: true,
message: "The to field is required to send an email."
});
would be great to be able to specify more than one error message because in most cases there isn't only one validation rule.
this.property("password", "string", {
assert: function(val) {
if (val.length <= 6 || val.length => 30) {
return false; // validation failed due to invalid length
} else if (val.match(/^[a-z0-9_]+$/) != val) {
return false; // not allowed characters in use
}
return true;
}
});
or
this.property("password", "string", {
assert: function(val) {
var errors = [];
if (val.length <= 6 || val.length => 30) {
errors[errors.length] = "validation failed due to invalid length";
}
if (val.match(/^[a-z0-9_]+$/) != val) {
errors[errors.length] = "not allowed characters in use";
}
return errors.length == 0;
}
});