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

Commit b0fcf39

Browse files
author
Gabriel Schulhof
committed
Checkboxradio: Always uncheck the rest of the input set upon input click
Closes gh-7183 Fixes gh-7180
1 parent b9b8fcf commit b0fcf39

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

js/widgets/forms/checkboxradio.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,9 @@ $.widget( "mobile.checkboxradio", $.extend( {
131131
},
132132

133133
_handleInputVClick: function() {
134-
var $this = this.element;
135-
136134
// Adds checked attribute to checked input when keyboard is used
137-
if ( $this.is( ":checked" ) ) {
138-
139-
$this.prop( "checked", true);
140-
this._getInputSet().not( $this ).prop( "checked", false );
141-
} else {
142-
$this.prop( "checked", false );
143-
}
144-
135+
this.element.prop( "checked", this.element.is( ":checked" ) );
136+
this._getInputSet().not( this.element ).prop( "checked", false );
145137
this._updateAll();
146138
},
147139

tests/unit/checkboxradio/checkboxradio_core.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
*/
44
(function($){
55
module( 'jquery.mobile.forms.checkboxradio.js' );
6+
test( "Programmatic click on radio input correctly updates group", function() {
7+
var first = $( "#programmatic-click-test input" ).eq( 0 ),
8+
last = $( "#programmatic-click-test input" ).eq( 2 );
9+
10+
last.click().checkboxradio( "refresh" );
11+
deepEqual( first.prop( "checked" ), false, "First checkboxradio prop is false" );
12+
deepEqual( first.prev( "label" ).hasClass( "ui-radio-off" ), true,
13+
"First label has class 'ui-radio-off'" );
14+
deepEqual( first.prev( "label" ).hasClass( "ui-radio-on" ), false,
15+
"First label does not have class 'ui-radio-on'" );
16+
deepEqual( last.prop( "checked" ), true, "Last checkboxradio prop is true" );
17+
deepEqual( last.prev( "label" ).hasClass( "ui-radio-off" ), false,
18+
"Last label does not have class 'ui-radio-off'" );
19+
deepEqual( last.prev( "label" ).hasClass( "ui-radio-on" ), true,
20+
"First label has class 'ui-radio-on'" );
21+
});
622

723
test( "widget with weird label is created successfully", function() {
824
var elem = $( "#chk\\[\\'3\\'\\]-1" );

tests/unit/checkboxradio/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
<div data-nstest-role="page" data-nstest-theme="b">
4141
<div data-nstest-role="content" id="the-content">
4242

43+
<div id="programmatic-click-test">
44+
<label>Radio 1<input type="radio" name="programmatic-click-test" checked></label>
45+
<label>Radio 2<input type="radio" name="programmatic-click-test"></label>
46+
<label>Radio 3<input type="radio" name="programmatic-click-test"></label>
47+
</div>
48+
4349
<input type="checkbox" id="chk['3']-1"></input>
4450
<label for="chk['3']-1">Checkbox label</label>
4551

0 commit comments

Comments
 (0)