Skip to content

Commit b33ec10

Browse files
author
Gabriel Schulhof
committed
Checkboxradio: refresh() has to check whether to disable or not
Closes jquery-archivegh-7600 Fixes jquery-archivegh-7598
1 parent 797516a commit b33ec10

File tree

3 files changed

+54
-20
lines changed

3 files changed

+54
-20
lines changed

js/widgets/forms/checkboxradio.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,13 @@ $.widget( "mobile.checkboxradio", $.extend( {
296296
},
297297

298298
refresh: function() {
299-
var hasIcon = this._hasIcon(),
300-
isChecked = this.element[ 0 ].checked,
299+
var isChecked = this.element[ 0 ].checked,
301300
active = $.mobile.activeBtnClass,
302301
iconposClass = "ui-btn-icon-" + this.options.iconpos,
303302
addClasses = [],
304303
removeClasses = [];
305304

306-
if ( hasIcon ) {
305+
if ( this._hasIcon() ) {
307306
removeClasses.push( active );
308307
addClasses.push( iconposClass );
309308
} else {
@@ -319,6 +318,8 @@ $.widget( "mobile.checkboxradio", $.extend( {
319318
removeClasses.push( this.checkedClass );
320319
}
321320

321+
this.widget().toggleClass( "ui-state-disabled", this.element.prop( "disabled" ) );
322+
322323
this.label
323324
.addClass( addClasses.join( " " ) )
324325
.removeClass( removeClasses.join( " " ) );

tests/unit/checkboxradio/checkboxradio_core.js

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,43 @@
2626
ok( elem.siblings( "label[for='chk\\[\\'3\\'\\]-1']" ).length === 1, "element has exactly one sibling of the form label[for='chk[\'3\']-1']" );
2727
});
2828

29-
test( "widget can be disabled and enabled", function(){
30-
var input = $( "#checkbox-1" ),
31-
button = input.parent().find( ".ui-btn" );
32-
33-
input.checkboxradio( "disable" );
34-
input.checkboxradio( "enable" );
35-
ok( !input.prop("disabled"), "start input as enabled" );
36-
ok( !input.parent().hasClass( "ui-state-disabled" ), "no disabled styles" );
37-
ok( !input.prop("checked"), "not checked before click" );
29+
function testEnableDisable( theInput, theMethod ) {
30+
var button = theInput.parent().find( ".ui-btn" );
31+
32+
theMethod( theInput, true );
33+
theMethod( theInput, false );
34+
ok( !theInput.prop("disabled"), "start input as enabled" );
35+
ok( !theInput.parent().hasClass( "ui-state-disabled" ), "no disabled styles" );
36+
ok( !theInput.prop("checked"), "not checked before click" );
3837
button.trigger( "click" );
39-
ok( input.prop("checked"), "checked after click" );
38+
ok( theInput.prop("checked"), "checked after click" );
4039
ok( button.hasClass( "ui-checkbox-on" ), "active styles after click" );
4140
button.trigger( "click" );
42-
input.checkboxradio( "disable" );
43-
ok( input.prop( "disabled" ), "input disabled" );
44-
ok( input.parent().hasClass( "ui-state-disabled" ), "disabled styles" );
45-
ok( !input.prop( "checked" ), "not checked before click" );
41+
theMethod( theInput, true );
42+
ok( theInput.prop( "disabled" ), "input disabled" );
43+
ok( theInput.parent().hasClass( "ui-state-disabled" ), "disabled styles" );
44+
ok( !theInput.prop( "checked" ), "not checked before click" );
4645
button.trigger( "click" );
47-
ok( !input.prop( "checked" ), "not checked after click" );
46+
ok( !theInput.prop( "checked" ), "not checked after click" );
4847
ok( !button.hasClass( "ui-checkbox-on" ), "no active styles after click" );
48+
}
49+
50+
test( "widget can be disabled and enabled via enable()/disable() method", function(){
51+
testEnableDisable( $( "#checkbox-disabled-test-1" ), function( theInput, isDisabled ) {
52+
theInput.checkboxradio( isDisabled ? "disable" : "enable" );
53+
});
54+
});
55+
56+
test( "widget can be disabled and enabled via option 'disabled'", function(){
57+
testEnableDisable( $( "#checkbox-disabled-test-2" ), function( theInput, isDisabled ) {
58+
theInput.checkboxradio( "option", "disabled", isDisabled );
59+
});
60+
});
61+
62+
test( "widget can be disabled and enabled via prop + refresh()", function(){
63+
testEnableDisable( $( "#checkbox-disabled-test-3" ), function( theInput, isDisabled ) {
64+
theInput.prop( "disabled", isDisabled ).checkboxradio( "refresh" );
65+
});
4966
});
5067

5168
test( "clicking a checkbox within a controlgroup does not affect checkboxes with the same name in the same controlgroup", function(){

tests/unit/checkboxradio/index.html

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,24 @@
6767
<div data-nstest-role="fieldcontain">
6868
<fieldset data-nstest-role="controlgroup">
6969
<legend>Agree to the terms:</legend>
70-
<input type="checkbox" name="checkbox-1" id="checkbox-1" class="custom"/>
71-
<label for="checkbox-1">I agree</label>
70+
<input type="checkbox" name="checkbox-disabled-test-1" id="checkbox-disabled-test-1" class="custom"/>
71+
<label for="checkbox-disabled-test-1">I agree</label>
72+
</fieldset>
73+
</div>
74+
75+
<div data-nstest-role="fieldcontain">
76+
<fieldset data-nstest-role="controlgroup">
77+
<legend>Agree to the terms:</legend>
78+
<input type="checkbox" name="checkbox-disabled-test-2" id="checkbox-disabled-test-2" class="custom"/>
79+
<label for="checkbox-disabled-test-2">I agree</label>
80+
</fieldset>
81+
</div>
82+
83+
<div data-nstest-role="fieldcontain">
84+
<fieldset data-nstest-role="controlgroup">
85+
<legend>Agree to the terms:</legend>
86+
<input type="checkbox" name="checkbox-disabled-test-3" id="checkbox-disabled-test-3" class="custom"/>
87+
<label for="checkbox-disabled-test-3">I agree</label>
7288
</fieldset>
7389
</div>
7490

0 commit comments

Comments
 (0)