How to display custom message from .addMethod using jQuery.Validator
I'm trying to make an ajax call, similar to the remote method only I need to take different action based upon the results from the ajax response. The ajax call works correctly, but the custom error message doesn't display.
- //Custom rule that performs an ajax call with custom messages.
$.validator.addMethod("validatePlace", function(value, element, params) {
if (this.optional(element))
return "dependency-mismatch";
$.get(params.url, params.data, function(response) {
var validator = $.validator;
if (response == "true") {
$("#<%=PanelAddress.ClientID %>").hide();
return true;
} else if (response == "ambiguous") {
$("#<%=PanelAddress.ClientID %>").hide();
var errors = {};
errors[element.name] = "Ambiguous, please select from the list.";
validator.showErrors(errors);
return false;
} else {
//Not found, enter address and display suggestion.
$("#<%=PanelAddress.ClientID %>").show();
var errors = {};
errors[element.name] = "Did you mean? <a href='#' onclick='UseSuggestion(" + escape(response) + ")'>" + response + "</a>";
validator.showErrors(errors);
return false;
}
});
//end function
});
I'm pretty sure the trouble is with validator.showErrors(), I don't think I'm doing it right. Please advise..