From c2927814d76b85af6ed7eed69cb358491859bba3 Mon Sep 17 00:00:00 2001 From: Stanislav Ievlev Date: Tue, 12 Feb 2013 17:24:14 +0400 Subject: [PATCH 1/2] Search for an item to compare in context of form --- jquery.validate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.validate.js b/jquery.validate.js index 3c02627ab..bdf938366 100644 --- a/jquery.validate.js +++ b/jquery.validate.js @@ -1152,7 +1152,7 @@ $.extend($.validator, { equalTo: function( value, element, param ) { // bind to the blur event of the target in order to revalidate whenever the target field is updated // TODO find a way to bind the event just once, avoiding the unbind-rebind overhead - var target = $(param); + var target = $(param, element.form); if ( this.settings.onfocusout ) { target.unbind(".validate-equalTo").bind("blur.validate-equalTo", function() { $(element).valid(); From e72815b757ea93aa763187427b63f310edec70f4 Mon Sep 17 00:00:00 2001 From: Stanislav Ievlev Date: Wed, 13 Feb 2013 12:13:32 +0400 Subject: [PATCH 2/2] Add unit tests for equalTo method with a "by-name" selector --- test/index.html | 6 ++++++ test/methods.js | 3 ++- test/test.js | 10 ++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/test/index.html b/test/index.html index bb9fc4ad8..0c4aae0f6 100644 --- a/test/index.html +++ b/test/index.html @@ -108,6 +108,11 @@

+
+ + +
+
@@ -181,6 +186,7 @@

+ diff --git a/test/methods.js b/test/methods.js index 36ddde727..a90f1967d 100644 --- a/test/methods.js +++ b/test/methods.js @@ -333,9 +333,10 @@ test("range", function() { test("equalTo", function() { var v = jQuery("#form").validate(); var method = $.validator.methods.equalTo, - e = $('#text1, #text2'); + e = $('#text1, #text2, #form input[name=text3]'); ok( method.call( v, "Test", e[0], "#text1"), "Text input" ); ok( method.call( v, "T", e[1], "#text2"), "Another one" ); + ok( method.call( v, "T", e[2], "input[name=text3]"), "Find by name" ); }); test("creditcard", function() { diff --git a/test/test.js b/test/test.js index 1b6589874..2232848b3 100644 --- a/test/test.js +++ b/test/test.js @@ -170,6 +170,16 @@ test("form(): with equalTo", function() { ok( v.form(), 'Valid form' ); }); +test("form(): with equalTo and selectors by name", function() { + expect( 2 ); + var form = $('#testForm5_1')[0]; + var v = $(form).validate(); + console.log("v.form=" + v.form()); + ok( !v.form(), 'Invalid form' ); + $('[name=x1], [name=x2]', form).val("hi"); + ok( v.form(), 'Valid form' ); +}); + test("form(): with equalTo and onfocusout=false", function() { expect( 4 ); var form = $('#testForm5')[0]; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy