#5262 closed bug (fixed)
Buttonset not working on inputs with Arrays in name Attribute
Reported by: | Zidane | Owned by: | Scott González |
---|---|---|---|
Priority: | blocker | Milestone: | 1.8 |
Component: | ui.button | Version: | 1.8rc3 |
Keywords: | buttonset input name array | Cc: | |
Blocked by: | Blocking: |
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 (8)
comment:1 Changed 14 years ago by
Milestone: | TBD → 1.8 |
---|---|
Priority: | minor → critical |
comment:2 Changed 14 years ago by
comment:3 Changed 14 years ago by
Priority: | critical → blocker |
---|
comment:5 Changed 14 years ago by
Quotes won't work for cases where there aren't matching brackets. So [name="foo[bar"] wouldn't work.
comment:6 Changed 14 years ago by
Owner: | set to scott.gonzalez |
---|---|
Status: | new → accepted |
comment:7 Changed 14 years ago by
Resolution: | → fixed |
---|---|
Status: | accepted → closed |
Fixed in r3869. I ended up using quotes because they do work even for unmatched brackets, despite what John said :-P
comment:8 Changed 13 years ago by
Hi,
I have exactly this problem when button is a checxkbox in jquery UI version 1.8.7, well it works with IE 8 but not with Firefox, Safari and Chrome.
The code is: find("[name='"+c+"']"):a("[name='"+c+"']"
We should escape the square brackets within the name instead of quoting.