Closed karlclement closed 8 years ago
errorTemplate is intended to return the html of the error message itself and is then insterted .after() the input element defined by the selector. It is given only one parameter, an error object w/ the id and message from the validator. There is currently no mechanism to insert the error as an attribute of the input defined by the selector.
Adding feature label to this since doing this (allowing the error message to go into a defined attribute of the selected element) would be a new feature.
How do I overwrite the default validation error?
Same problem here. Need an example of errorTemplate usage.
All it does is take the error object and return the html you want inserted as your 'rendered' error.
function customErrorTemplate(error) {
//error is {id: errorId, message: 'validation error message'}
return $("<p class='something' id='" + error.id + ">" + error.message + "</p>");
}
Custom error messages have been added as of v0.9.
To change the error message, return an instance of Error
. For example:
$('#form').isHappy({
fields: {
'#birthday': {
required: true,
test: function() {
if(isEmpty) {
return false;
}
if(isFuture) {
return new Error(‘Your birthday must have already happened.’);
}
if (isWednesday) {
return new Error(‘Your birthday cannot have happened on a Wednesday.’);
}
return true;
},
message: ‘Please provide a valid birth date.'
}
}
});
I would like to overwrite the way the error message is handled. I want to use the id of the field to select it and them use the placeholder attribute to show the error message.
How do I overwrite the default validation error?
This is what I have:
I keep getting these error on validation error:
Any help?