Bugfixes for compability with jQuery 1.4.2, while maintaining backwards-compability

This commit is contained in:
Jörn Zaeffferer
2010-03-08 23:31:24 +00:00
parent 61162bde0b
commit 6ba056b138
4 changed files with 16 additions and 23 deletions

View File

@@ -11,6 +11,7 @@
* Renamed phone-method in additional-methods.js to phoneUS
* Added phoneUK and mobileUK methods to additional-methods.js (http://plugins.jquery.com/node/12359)
* Deep extend options to avoid modifying multiple forms when using the rules-method on a single element (http://plugins.jquery.com/node/12411)
* Bugfixes for compability with jQuery 1.4.2, while maintaining backwards-compability
1.6
---

18
jquery.validate.js vendored
View File

@@ -300,12 +300,13 @@ $.extend($.validator, {
});
function delegate(event) {
var validator = $.data(this[0].form, "validator");
validator.settings["on" + event.type] && validator.settings["on" + event.type].call(validator, this[0] );
var validator = $.data(this[0].form, "validator"),
eventType = "on" + event.type.replace(/^validate/, "");
validator.settings[eventType] && validator.settings[eventType].call(validator, this[0] );
}
$(this.currentForm)
.delegate("focusin focusout keyup", ":text, :password, :file, select, textarea", delegate)
.delegate("click", ":radio, :checkbox, select, option", delegate);
.validateDelegate(":text, :password, :file, select, textarea", "validatefocusin validatefocusout keyup", delegate)
.validateDelegate(":radio, :checkbox, select, option", "click", delegate);
if (this.settings.invalidHandler)
$(this.currentForm).bind("invalid-form.validate", this.settings.invalidHandler);
@@ -1104,8 +1105,8 @@ $.format = $.validator.format;
// provides triggerEvent(type: String, target: Element) to trigger delegated events
;(function($) {
$.each({
focus: 'focusin',
blur: 'focusout'
focus: 'validatefocusin',
blur: 'validatefocusout'
}, function( original, fix ){
$.event.special[fix] = {
setup:function() {
@@ -1125,16 +1126,13 @@ $.format = $.validator.format;
};
});
$.extend($.fn, {
delegate: function(type, delegate, handler) {
validateDelegate: function(delegate, type, handler) {
return this.bind(type, function(event) {
var target = $(event.target);
if (target.is(delegate)) {
return handler.apply(target, arguments);
}
});
},
triggerEvent: function(type, target) {
return this.triggerHandler(type, [$.event.fix({ type: type, target: target })]);
}
});
})(jQuery);

View File

@@ -24,7 +24,7 @@
<input type="password" name="pw1" id="pw1" value="engfeh" />
<input type="password" name="pw2" id="pw2" value="" />
</div>
<div id="main" style="display:none;">
<div id="main" style="position: absolute; top: -10000px; left: -10000px;">
<p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a> for more information.</p>
<p id="ap">
Here are some links in a normal paragraph: <a id="google" href="http://www.google.com/" title="Google!">Google</a>,

View File

@@ -574,15 +574,9 @@ test("findLastActive()", function() {
ok( !v.findLastActive() );
v.form();
v.focusInvalid();
ok( !v.findLastActive() );
try {
$("#testForm1 input:last").trigger("focusin");
//$("#testForm1").triggerEvent("focusin", $("#testForm1 input:last")[0]);
v.focusInvalid();
equals( lastInput, v.findLastActive() );
} catch(e) {
ok( true, "Ignore in IE" );
}
equals( v.findLastActive(), $("#firstname")[0] );
var lastActive = $("#lastname").trigger("validatefocusin")[0];
equals( v.findLastActive(), lastActive );
});
test("validating multiple checkboxes with 'required'", function() {
@@ -877,7 +871,7 @@ test("validate on blur", function() {
equals(v.errors().filter(":visible").size(), expected);
}
function blur(target) {
target.trigger("focusout");
target.trigger("validatefocusout");
}
$("#errorFirstname").hide();
var e = $("#firstname");
@@ -954,7 +948,7 @@ test("validate on not keyup, only blur", function() {
e.trigger("keyup");
e.keyup();
errors(0);
e.trigger("focusout");
e.trigger("validatefocusout");
errors(1);
});
@@ -968,7 +962,7 @@ test("validate on keyup and blur", function() {
e.val("a");
e.trigger("keyup");
errors(0);
e.trigger("focusout");
e.trigger("validatefocusout");
errors(1);
});