Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search for an item to compare in context of form #637

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion jquery.validate.js
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions test/index.html
Expand Up @@ -108,6 +108,11 @@ <h2 id="qunit-userAgent"></h2>
<input data-rule-equalto="#x1" value="y" name="x2" id="x2" />
</form>

<form id="testForm5_1">
<input data-rule-equalto="[name=x2]" value="x" name="x1" />
<input data-rule-equalto="[name=x1]" value="y" name="x2" />
</form>

<form id="testForm6">
<input data-rule-required="true" data-rule-minlength="2" type="checkbox" name="check" id="form6check1" />
<input type="checkbox" name="check" id="form6check2" />
Expand Down Expand Up @@ -181,6 +186,7 @@ <h3></h3>
<input type="text" name="text2" value="T " id="text1c"/>
<input type="text" name="text2" value="T" id="text2"/>
<input type="text" name="text2" value="TestTestTest" id="text3"/>
<input type="text" name="text3" value="T"/>

<input type="text" name="action" value="0" id="value1"/>
<input type="text" name="text2" value="10" id="value2"/>
Expand Down
3 changes: 2 additions & 1 deletion test/methods.js
Expand Up @@ -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() {
Expand Down
10 changes: 10 additions & 0 deletions test/test.js
Expand Up @@ -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];
Expand Down