Skip to content

Commit

Permalink
Core: Ignore events on ignored elements
Browse files Browse the repository at this point in the history
When an ignored element produces a blur event, it causes the valid() method to
return the wrong value.

Fixes gh-700
Closes gh-705
  • Loading branch information
ruado1987 authored and jzaefferer committed Jan 14, 2014
1 parent f7a2592 commit a864211
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,10 @@ $.extend($.validator, {

function delegate(event) {
var validator = $.data(this[0].form, "validator"),
eventType = "on" + event.type.replace(/^validate/, "");
if ( validator.settings[eventType] ) {
validator.settings[eventType].call(validator, this[0], event);
eventType = "on" + event.type.replace(/^validate/, ""),
settings = validator.settings;
if ( settings[eventType] && !this.is( settings.ignore ) ) {
settings[eventType].call(validator, this[0], event);
}
}
$(this.currentForm)
Expand Down
9 changes: 9 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,15 @@ <h3></h3>
<input type="text" name="ariaRequiredData" id="ariaRequiredData" data-rule-required="true" />
<input type="text" name="ariaRequiredClass" id="ariaRequiredClass" class="required" />
</form>

<form id="ignoredElements">
<select id="ss1" class="ignore">
<option value="1">option 1</option>
<option value="2">option 2</option>
</select>
<br />
<input name="test" class="required" value=""/>
</form>
</div>

</body>
Expand Down
14 changes: 14 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,20 @@ test("Min and Max strings set by attributes valid", function() {
equal( label.text(), "", "Correct error label" );
});

test( "calling blur on ignored element", function() {
var form = $( "#ignoredElements" );

form.validate({
ignore: '.ignore',
submitHandler: $.noop,
invalidHandler: function() {
$( "#ss1" ).blur();
}
});

form.trigger( "submit" );
equal( form.valid(), false, "valid() should return false" );
});


test("Min and Max type absent set by attributes greater", function() {
Expand Down

0 comments on commit a864211

Please sign in to comment.