Skip to content

Commit 8511132

Browse files
committed
Checkboxradio: fixup
1 parent 62904f1 commit 8511132

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

tests/unit/checkboxradio/checkboxradio_core.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,12 @@ test( "Checkbox label selector works for ids with \":\"", function() {
141141
ok( group.find( "label" ).is( ".ui-button" ), "Found an id with a :" );
142142
});
143143

144-
test( "Calling checkboxradio on an unsupported element throws and error", function() {
144+
test( "Calling checkboxradio on an unsupported element throws an error", function() {
145145
expect( 1 );
146146
throws( $( "<div>" ).checkboxradio, "Error thrown" );
147147
});
148+
test( "Calling checkboxradio oan input with no label throws an error", function() {
149+
expect( 1 );
150+
throws( $( "<input type='checkbox'>" ).checkboxradio, "Error thrown" );
151+
});
148152
})(jQuery);

ui/checkboxradio.js

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,6 @@ $.widget( "ui.checkboxradio", {
8989
return options;
9090
},
9191

92-
_readDisabled: function( options ) {
93-
var isDisabled = this.element.prop( "disabled" );
94-
95-
if ( isDisabled !== undefined ) {
96-
options.disabled = isDisabled;
97-
} else {
98-
options.disabled = false;
99-
}
100-
},
101-
10292
_create: function() {
10393
var formElement = $( this.element[ 0 ].form );
10494

@@ -107,17 +97,10 @@ $.widget( "ui.checkboxradio", {
10797
formElement.off( "reset" + this.eventNamespace, formResetHandler );
10898
formElement.on( "reset" + this.eventNamespace, formResetHandler );
10999

110-
// If it is null the user set it explicitly to null so we need to check the DOM
111100
if ( this.options.disabled == null ) {
112101
this.options.disabled = this.element.prop( "disabled" ) || false;
113102
}
114103

115-
// If the option is true we call set options to add the disabled
116-
// classes and ensure the element is not focused
117-
if ( this.options.disabled === true ){
118-
this._setOption( "disabled", true );
119-
}
120-
121104
this._readType();
122105

123106
this._enhance();
@@ -141,7 +124,9 @@ $.widget( "ui.checkboxradio", {
141124
},
142125

143126
_readLabel: function() {
144-
var ancestor, labelSelector, parent = this.element.closest( "label" );
127+
var ancestor, labelSelector,
128+
parent = this.element.closest( "label" );
129+
145130
// Check control.labels first
146131
if ( this.element[ 0 ].labels !== undefined && this.element[ 0 ].labels.length > 0 ){
147132
this.label = $( this.element[ 0 ].labels[ 0 ] );
@@ -158,8 +143,8 @@ $.widget( "ui.checkboxradio", {
158143
this.label = ancestor.find( labelSelector );
159144
if ( !this.label.length ) {
160145

161-
// The label was not found make sure ancestors exist if they do check their siblings
162-
// if they dont check the elements siblings
146+
// The label was not found, make sure ancestors exist. If they do check their
147+
// siblings, if they dont check the elements siblings
163148
ancestor = ancestor.length ? ancestor.siblings() : this.element.siblings();
164149

165150
// Check if any of the new set of ancestors is the label
@@ -168,6 +153,9 @@ $.widget( "ui.checkboxradio", {
168153

169154
// Still not found look inside the ancestors for the label
170155
this.label = ancestor.find( labelSelector );
156+
if ( this.label.length === 0 ) {
157+
$.error( "No label found for checkboxradio widget" );
158+
}
171159
}
172160
}
173161
}
@@ -176,6 +164,7 @@ $.widget( "ui.checkboxradio", {
176164
_enhance: function() {
177165
var checked = this.element.is( ":checked" );
178166

167+
this._setOption( "disabled", this.options.disabled );
179168
this._updateIcon( checked );
180169
this.element.addClass( "ui-helper-hidden-accessible " +
181170
this._classes( "ui-checkboxradio" ) );

0 commit comments

Comments
 (0)