Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 75594d2

Browse files
author
Gabriel Schulhof
committed
[checkboxradio] Determination as to whether the widget is inside a horizontal controlgroup or not needs to be made during refresh(), not during _create(), because otherwise an already-enhanced checkbox added to a horizontal controlgroup will not start using the activeBtnClass to render its checked state and neither will checkboxes initially added to a vertical controlgroup which is then converted to a horizontal controlgroup
1 parent bbe5b8c commit 75594d2

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

js/widgets/forms/checkboxradio.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,9 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
3434
mini = inheritAttr( input, "mini" ) || o.mini,
3535
checkedState = inputtype + "-on",
3636
uncheckedState = inputtype + "-off",
37-
icon = uncheckedState,
3837
iconpos = inheritAttr( input, "iconpos" ),
39-
horizontal = input.parents( ":jqmData(type='horizontal')" ).length,
40-
activeBtn = $.mobile.activeBtnClass,
4138
checkedClass = "ui-" + checkedState,
42-
uncheckedClass = "ui-" + uncheckedState,
43-
checkedicon = icon ? checkedState : undefined,
44-
uncheckedicon = icon ? uncheckedState : undefined;
39+
uncheckedClass = "ui-" + uncheckedState;
4540

4641
if ( inputtype !== "checkbox" && inputtype !== "radio" ) {
4742
return;
@@ -51,12 +46,10 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
5146
$.extend( this, {
5247
label: label,
5348
inputtype: inputtype,
54-
horizontal: horizontal,
55-
activeBtn: activeBtn,
5649
checkedClass: checkedClass,
5750
uncheckedClass: uncheckedClass,
58-
checkedicon: checkedicon,
59-
uncheckedicon: uncheckedicon
51+
checkedicon: checkedState,
52+
uncheckedicon: uncheckedState
6053
});
6154

6255
// If there's no selected theme check the data attr
@@ -66,7 +59,7 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
6659

6760
label.buttonMarkup({
6861
theme: o.theme,
69-
icon: icon,
62+
icon: uncheckedState,
7063
shadow: false,
7164
mini: mini,
7265
iconpos: iconpos
@@ -183,19 +176,25 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
183176
},
184177

185178
refresh: function() {
186-
var input = this.element[0],
187-
label = this.label;
188-
189-
if ( this.horizontal ) {
190-
this.checkedClass = this.checkedClass + " " + this.activeBtn;
191-
}
179+
var input = this.element[ 0 ],
180+
horizontal = this.element.parents( ".ui-controlgroup-horizontal" ).length,
181+
active = " " + $.mobile.activeBtnClass,
182+
checkedClass = this.checkedClass + ( horizontal ? active : "" ),
183+
icon, label = this.label;
192184

193185
if ( input.checked ) {
194-
label.addClass( this.checkedClass ).removeClass( this.uncheckedClass ).buttonMarkup( { icon: this.checkedicon } );
186+
label.removeClass( this.uncheckedClass + active ).addClass( checkedClass );
187+
icon = this.checkedicon;
195188
} else {
196-
label.removeClass( this.checkedClass ).addClass( this.uncheckedClass ).buttonMarkup( { icon: this.uncheckedicon } );
189+
label.removeClass( checkedClass ).addClass( this.uncheckedClass );
190+
icon = this.uncheckedicon;
191+
}
192+
if ( horizontal ) {
193+
icon = undefined;
197194
}
198195

196+
label.buttonMarkup( { icon: icon } );
197+
199198
if ( input.disabled ) {
200199
this.disable();
201200
} else {

0 commit comments

Comments
 (0)