Im trying to add a custom validation method to jquery validation plugin. When I try to attach the rule to an element I receive an error "uniqueTicket" not defined.
Here is my add method:
jQuery.validator.addMethod("uniqueTicket", function (value, element, param) {
var data = {
ticket: value,
reservation_id: $("#reservation_id").val()
};
if (value.length > 3) {
$.ajax({
type: "POST",
url: '/ticketaudits/validateTicket',
data: data,
dataType: "json",
success: function (msg) {
//If username exists, set response to true
response = (msg == 'true') ? true : false;
}
});
} else {
response = false;
}
return response;
},
"Ticket is invalid or already used");
This is being called within the same document ready function as the validation. My validation is:
$('#myForm').validate({
debug: false,
ignoreTitle: true,
onkeyup: false,
rules: {
ticket: uniqueTicket
}
});
I've followed a number of examples for this but don't understand the problem. Does this mean there's an error in my addmethod?