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

Commit

Permalink
Checkboxradio: Correctly assemble radio group
Browse files Browse the repository at this point in the history
Closes gh-6659
Closes gh-7082
Fixes gh-7088
  • Loading branch information
Gabriel Schulhof committed Feb 17, 2014
1 parent d60fdc3 commit f797e4d
Showing 1 changed file with 47 additions and 7 deletions.
54 changes: 47 additions & 7 deletions js/widgets/forms/checkboxradio.js
Expand Up @@ -10,12 +10,15 @@
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css

define( [ "jquery",
"../../navigation/path",
"../../jquery.mobile.core",
"../../jquery.mobile.widget",
"./reset" ], function( jQuery ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {

var escapeId = $.mobile.path.hashToSelector;

$.widget( "mobile.checkboxradio", $.extend( {

initSelector: "input:not( :jqmData(role='flipswitch' ) )[type='checkbox'],input[type='radio']:not( :jqmData(role='flipswitch' ))",
Expand All @@ -42,7 +45,7 @@ $.widget( "mobile.checkboxradio", $.extend( {
input
.closest( "form, fieldset, :jqmData(role='page'), :jqmData(role='dialog')" )
.find( "label" )
.filter( "[for='" + $.mobile.path.hashToSelector( input[0].id ) + "']" )
.filter( "[for='" + escapeId( input[0].id ) + "']" )
.first(),
inputtype = input[0].type,
checkedClass = "ui-" + inputtype + "-on",
Expand Down Expand Up @@ -182,14 +185,51 @@ $.widget( "mobile.checkboxradio", $.extend( {
});
},

//returns either a set of radios with the same name attribute, or a single checkbox
// Returns those radio buttons that are supposed to be in the same group as
// this radio button. In the case of a checkbox or a radio lacking a name
// attribute, it returns this.element.
_getInputSet: function() {
if ( this.inputtype === "checkbox" ) {
return this.element;
var selector, formId,
radio = this.element[ 0 ],
name = radio.name,
form = radio.form,
doc = radio.ownerDocument,

// A radio is always a member of its own group
radios = this.element;

// Only start running selectors if this is a radio button with a name
if ( name && this.inputtype === "radio" ) {
selector = "input[type='radio'][name='" + escapeId( name ) + "']";

// If we're inside a form ...
if ( form ) {
formId = form.id;

// ... and the form has an ID, collect radios scattered throught the document which
// nevertheless are part of the form by way of the value of their form attribute
if ( formId ) {
radios = $( selector + "[form='" + escapeId( formId ) + "']", doc );
}

// ... and add to those the radios in the form itself
radios = $( form ).find( selector ).filter( function() {

// ... but some radios inside the form may belong to some other form by virtue
// of having a form attribute defined on them, so we must filter them out here
return ( this.form === form );
}).add( radios );

// Otherwise, if we're outside a form ...
} else {

// ... collect all those radios which are also outside of a form and match our name
radios = $( selector, doc ).filter( function() {
return !this.form;
});
}
}

return this.element.closest( "form, :jqmData(role='page'), :jqmData(role='dialog')" )
.find( "input[name='" + this.element[ 0 ].name + "'][type='" + this.inputtype + "']" );
return radios;
},

_updateAll: function() {
Expand Down

0 comments on commit f797e4d

Please sign in to comment.