1010//>>css.theme: ../css/themes/default/jquery.mobile.theme.css
1111
1212define ( [ "jquery" ,
13+ "../../navigation/path" ,
1314 "../../jquery.mobile.core" ,
1415 "../../jquery.mobile.widget" ,
1516 "./reset" ] , function ( jQuery ) {
1617//>>excludeEnd("jqmBuildExclude");
1718( function ( $ , undefined ) {
1819
20+ var escapeId = $ . mobile . path . hashToSelector ;
21+
1922$ . widget ( "mobile.checkboxradio" , $ . extend ( {
2023
2124 initSelector : "input:not( :jqmData(role='flipswitch' ) )[type='checkbox'],input[type='radio']:not( :jqmData(role='flipswitch' ))" ,
@@ -42,7 +45,7 @@ $.widget( "mobile.checkboxradio", $.extend( {
4245 input
4346 . closest ( "form, fieldset, :jqmData(role='page'), :jqmData(role='dialog')" )
4447 . find ( "label" )
45- . filter ( "[for='" + $ . mobile . path . hashToSelector ( input [ 0 ] . id ) + "']" )
48+ . filter ( "[for='" + escapeId ( input [ 0 ] . id ) + "']" )
4649 . first ( ) ,
4750 inputtype = input [ 0 ] . type ,
4851 checkedClass = "ui-" + inputtype + "-on" ,
@@ -182,14 +185,51 @@ $.widget( "mobile.checkboxradio", $.extend( {
182185 } ) ;
183186 } ,
184187
185- //returns either a set of radios with the same name attribute, or a single checkbox
188+ // Returns those radio buttons that are supposed to be in the same group as
189+ // this radio button. In the case of a checkbox or a radio lacking a name
190+ // attribute, it returns this.element.
186191 _getInputSet : function ( ) {
187- if ( this . inputtype === "checkbox" ) {
188- return this . element ;
192+ var selector , formId ,
193+ radio = this . element [ 0 ] ,
194+ name = radio . name ,
195+ form = radio . form ,
196+ doc = this . element . parents ( ) . last ( ) . get ( 0 ) ,
197+
198+ // A radio is always a member of its own group
199+ radios = this . element ;
200+
201+ // Only start running selectors if this is an attached radio button with a name
202+ if ( name && this . inputtype === "radio" && doc ) {
203+ selector = "input[type='radio'][name='" + escapeId ( name ) + "']" ;
204+
205+ // If we're inside a form
206+ if ( form ) {
207+ formId = form . id ;
208+
209+ // If the form has an ID, collect radios scattered throught the document which
210+ // nevertheless are part of the form by way of the value of their form attribute
211+ if ( formId ) {
212+ radios = $ ( selector + "[form='" + escapeId ( formId ) + "']" , doc ) ;
213+ }
214+
215+ // Also add to those the radios in the form itself
216+ radios = $ ( form ) . find ( selector ) . filter ( function ( ) {
217+
218+ // Some radios inside the form may belong to some other form by virtue of
219+ // having a form attribute defined on them, so we must filter them out here
220+ return ( this . form === form ) ;
221+ } ) . add ( radios ) ;
222+
223+ // If we're outside a form
224+ } else {
225+
226+ // Collect all those radios which are also outside of a form and match our name
227+ radios = $ ( selector , doc ) . filter ( function ( ) {
228+ return ! this . form ;
229+ } ) ;
230+ }
189231 }
190-
191- return this . element . closest ( "form, :jqmData(role='page'), :jqmData(role='dialog')" )
192- . find ( "input[name='" + this . element [ 0 ] . name + "'][type='" + this . inputtype + "']" ) ;
232+ return radios ;
193233 } ,
194234
195235 _updateAll : function ( ) {
0 commit comments