mirror of
https://github.com/jquery-validation/jquery-validation.git
synced 2025-12-20 09:11:40 +01:00
Move remote method down the list to run last, after all other methods applied to a field. Fixes #679
This commit is contained in:
108
jquery.validate.js
vendored
108
jquery.validate.js
vendored
@@ -998,60 +998,6 @@ $.extend($.validator, {
|
|||||||
return $.trim(value).length > 0;
|
return $.trim(value).length > 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
// http://docs.jquery.com/Plugins/Validation/Methods/remote
|
|
||||||
remote: function( 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] = {};
|
|
||||||
}
|
|
||||||
previous.originalMessage = this.settings.messages[element.name].remote;
|
|
||||||
this.settings.messages[element.name].remote = previous.message;
|
|
||||||
|
|
||||||
param = typeof param === "string" && {url:param} || param;
|
|
||||||
|
|
||||||
if ( previous.old === value ) {
|
|
||||||
return previous.valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 ) {
|
|
||||||
validator.settings.messages[element.name].remote = previous.originalMessage;
|
|
||||||
var valid = response === true || response === "true";
|
|
||||||
if ( valid ) {
|
|
||||||
var submitted = validator.formSubmitted;
|
|
||||||
validator.prepareElement(element);
|
|
||||||
validator.formSubmitted = submitted;
|
|
||||||
validator.successList.push(element);
|
|
||||||
delete validator.invalid[element.name];
|
|
||||||
validator.showErrors();
|
|
||||||
} else {
|
|
||||||
var errors = {};
|
|
||||||
var message = response || validator.defaultMessage( element, "remote" );
|
|
||||||
errors[element.name] = previous.message = $.isFunction(message) ? message(value) : message;
|
|
||||||
validator.invalid[element.name] = true;
|
|
||||||
validator.showErrors(errors);
|
|
||||||
}
|
|
||||||
previous.valid = valid;
|
|
||||||
validator.stopRequest(element, valid);
|
|
||||||
}
|
|
||||||
}, param));
|
|
||||||
return "pending";
|
|
||||||
},
|
|
||||||
|
|
||||||
// http://docs.jquery.com/Plugins/Validation/Methods/email
|
// http://docs.jquery.com/Plugins/Validation/Methods/email
|
||||||
email: function( value, element ) {
|
email: function( value, element ) {
|
||||||
// contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
|
// contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
|
||||||
@@ -1159,6 +1105,60 @@ $.extend($.validator, {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
return value === target.val();
|
return value === target.val();
|
||||||
|
},
|
||||||
|
|
||||||
|
// http://docs.jquery.com/Plugins/Validation/Methods/remote
|
||||||
|
remote: function( 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] = {};
|
||||||
|
}
|
||||||
|
previous.originalMessage = this.settings.messages[element.name].remote;
|
||||||
|
this.settings.messages[element.name].remote = previous.message;
|
||||||
|
|
||||||
|
param = typeof param === "string" && {url:param} || param;
|
||||||
|
|
||||||
|
if ( previous.old === value ) {
|
||||||
|
return previous.valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 ) {
|
||||||
|
validator.settings.messages[element.name].remote = previous.originalMessage;
|
||||||
|
var valid = response === true || response === "true";
|
||||||
|
if ( valid ) {
|
||||||
|
var submitted = validator.formSubmitted;
|
||||||
|
validator.prepareElement(element);
|
||||||
|
validator.formSubmitted = submitted;
|
||||||
|
validator.successList.push(element);
|
||||||
|
delete validator.invalid[element.name];
|
||||||
|
validator.showErrors();
|
||||||
|
} else {
|
||||||
|
var errors = {};
|
||||||
|
var message = response || validator.defaultMessage( element, "remote" );
|
||||||
|
errors[element.name] = previous.message = $.isFunction(message) ? message(value) : message;
|
||||||
|
validator.invalid[element.name] = true;
|
||||||
|
validator.showErrors(errors);
|
||||||
|
}
|
||||||
|
previous.valid = valid;
|
||||||
|
validator.stopRequest(element, valid);
|
||||||
|
}
|
||||||
|
}, param));
|
||||||
|
return "pending";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user