Ticket #5262 (closed bug: fixed)
Buttonset not working on inputs with Arrays in name Attribute
| Reported by: | Zidane | Owned by: | scott.gonzalez |
|---|---|---|---|
| Priority: | blocker | Milestone: | 1.8 |
| Component: | ui.button | Version: | 1.8rc3 |
| Keywords: | buttonset input name array | Cc: | |
| Blocking: | Blocked by: |
Description
Issue
I had some radiobuttons on my page. They all had a name with arrays (happens quite a lot with cakePHP). As an example one of those radiobuttons:
<input type="radio" id="option1" name="data[Options][Fieldname]" value="1" /><label for="option1">Test1</label>
When I tried to use a buttonset on a group of these (with the same name) the buttonset did not work correctly: When clicked I could activate all the buttons which should not work with radiobuttons. But I could not deactivate any of the buttons.
Solution
After a little search in the source I found a solution that works for me... I had to alter 2 lines in the jquery.ui.button.js file:
The 2 lines:
radios = $( form ).find( "[name=" + name + "]" );
radios = $( "[name=" + name + "]", radio.ownerDocument )
My change: Replacing the
"[name=" + name + "]"
with
'[name="' + name + '"]'
So that the name variable doesn't break the jQuery attribute when it contains array-brackets.
Change History
comment:1 Changed 3 years ago by scott.gonzalez
- Priority changed from minor to critical
- Milestone changed from TBD to 1.8
comment:2 Changed 3 years ago by scott.gonzalez
We should escape the square brackets within the name instead of quoting.
comment:5 Changed 3 years ago by scott.gonzalez
Quotes won't work for cases where there aren't matching brackets. So [name="foo[bar"] wouldn't work.
comment:6 Changed 3 years ago by scott.gonzalez
- Owner set to scott.gonzalez
- Status changed from new to accepted

