[jQuery] (validate)
hi there i'm working with the remote method of validator plug-in to
have in response validity and a message... and i have it working!
the plugin show the remote msg ok but on lost focus i get:
Warning: No message defined for DE1695
the remote script always return {valid:tue,msg:somemsg}
test input (not valid ) 20-24006411-2
any other number with the same format will be ok.
test page: www.accionpyme.mecon.gov.ar/dna2/TEST/CUIT.php
the method:
function remotemsg(value, element, param) {
if ( this.optional(element) )
return "dependency-mismatch";
var previous = this.previousValue(element);
if (!this.settings.messages[element.name] )
this.settings.messages[element.name] = {};
//this.settings.messages[element.name].remote = typeof
previous.message == "function" ? previous.message(value) :
previous.message;
param = typeof param == "string" && {url:param} || param;
if ( previous.old !== value ) {
previous.old = value;
var validator = this;
this.startRequest(element);
var data = {};
data[element.name] = value;
$.ajax($.extend(true, {
url: param,
mode: "abort",
port: "validate" + element.name,
dataType: "json",
data: data,
success: function(response) {
console.log(response.msg);
var valid = response.valid === true;
if ( valid ) {
var submitted = validator.formSubmitted;
validator.prepareElement(element);
validator.formSubmitted = submitted;
validator.successList.push(element);
validator.showErrors();
} else {
var errors = {};
errors[element.name] = response.msg;
validator.showErrors(errors);
}
previous.valid = valid;
validator.stopRequest(element, valid);
}
}, param));
return "pending";
} else if( this.pending[element.name] ) {
return "pending";
}
return previous.valid;
}
jQuery.validator.addMethod("CUITR", remotemsg,false);
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home