Skip to content

Commit

Permalink
use getAttribute in preference to the :checked selector to fix issues…
Browse files Browse the repository at this point in the history
… with many inputs Fixes jquery-archive#3597
  • Loading branch information
johnbender committed Feb 22, 2012
1 parent 1c29a20 commit a4170c4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
4 changes: 3 additions & 1 deletion js/jquery.mobile.forms.checkboxradio.js
Expand Up @@ -159,7 +159,9 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
this._getInputSet().each(function() {
var $this = $(this);

if ( $this.is( ":checked" ) || self.inputtype === "checkbox" ) {
// NOTE getAttribute is used here to deal with an issue with the :checked
// selector. see #3597
if ( this.getAttribute( "checked" ) || self.inputtype === "checkbox" ) {
$this.trigger( "change" );
}
})
Expand Down
24 changes: 22 additions & 2 deletions tests/unit/checkboxradio/checkboxradio_core.js
Expand Up @@ -113,7 +113,6 @@
singleActiveAndChecked();

start();
console.log( "ignore" );
}
], 500);

Expand All @@ -130,7 +129,7 @@
test( "checkboxradio elements in the keepNative set shouldn't be enhanced", function() {
ok( !$("input.should-be-native").parent().is("div.ui-checkbox") );
});

test( "Elements with “data-mini='true'” should have “ui-mini” class attached to enhanced element.", function(){
var full = document.getElementById("radio-full"),
$fulllbl = $('[for="radio-full"]'),
Expand Down Expand Up @@ -162,4 +161,25 @@
}
], 2000);
});

asyncTest( "clicking the label triggers a change on the element", function() {
var changed = false;

expect( 1 );

$( "#checkbox-change-triggered" ).one('change', function() {
changed = true;
});

$.testHelper.sequence([
function() {
$( "[for='checkbox-change-triggered']" ).click();
},

function() {
ok(changed, "change was fired on input");
start();
}
], 2000);
});
})(jQuery);
7 changes: 7 additions & 0 deletions tests/unit/checkboxradio/index.html
Expand Up @@ -114,6 +114,13 @@ <h2 id="qunit-userAgent"></h2>
<legend>Agree to the terms:</legend>
<input type="checkbox" name="checkbox-click-triggered" id="checkbox-click-triggered"/>
<label for="checkbox-click-triggered">click triggered</label>
<input type="checkbox" name="checkbox-click-triggered" id="checkbox-click-triggered-2"/>
<label for="checkbox-click-triggered-2">click triggered</label>

<input type="radio" name="checkbox-change-triggered" id="checkbox-change-triggered"/>
<label for="checkbox-change-triggered">click triggered</label>
<input type="radio" name="checkbox-change-triggered" id="checkbox-change-triggered-2"/>
<label for="checkbox-change-triggered-2">click triggered</label>
</fieldset>
</div>
</div>
Expand Down

0 comments on commit a4170c4

Please sign in to comment.