Opened 9 years ago
Closed 9 years ago
#9570 closed bug (duplicate)
Error on radio and non-radio input sharing a name
Reported by: | ardoramor | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | none |
Component: | ui.button | Version: | 1.9.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
For the purposes of my development, I have a case where my form has a series of radio buttons and an input type="text" with the same name. The issue comes in when toggling one of the radio buttons. The code uses a function radioGroup only for radio buttons but does not ensure that it only selects radios:
radioGroup = function( radio ) { var name = radio.name, form = radio.form, radios = $( [] ); if ( name ) { if ( form ) { radios = $( form ).find( "[name='" + name + "']" ); } else { radios = $( "[name='" + name + "']", radio.ownerDocument ) .filter(function() { return !this.form; }); } } return radios; };
The result is the following uncaught exception: Uncaught Error: cannot call methods on button prior to initialization; attempted to call method 'widget'.
The change should be the addition of [type="radio"] as follows:
radios = $( form ).find( "[name='" + name + "'][type='radio']" );
radios = $( "[name='" + name + "'][type='radio']", radio.ownerDocument )
HTML spec does not forbid assigning the same name to inputs. These inputs will be serialized. As such, jQueryUI should handle such case appropriately and only attempt to apply modifications to proper elements.
Duplicate of #9386.