Skip to main content

Search and Top Navigation

#5262 closed bug (fixed)

Opened March 02, 2010 11:01PM UTC

Closed March 04, 2010 02:01AM UTC

Last modified January 01, 2011 01:58PM UTC

Buttonset not working on inputs with Arrays in name Attribute

Reported by: Zidane Owned by: scottgonzalez
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.

Attachments (0)
Change History (8)

Changed March 03, 2010 02:21AM UTC by scottgonzalez comment:1

milestone: TBD1.8
priority: minorcritical

Changed March 03, 2010 05:58PM UTC by scottgonzalez comment:2

We should escape the square brackets within the name instead of quoting.

Changed March 03, 2010 06:02PM UTC by scottgonzalez comment:3

priority: criticalblocker

Changed March 03, 2010 11:00PM UTC by jzaefferer comment:4

Whats wrong with the quotes?

Changed March 04, 2010 01:34AM UTC by scottgonzalez comment:5

Quotes won't work for cases where there aren't matching brackets. So [name="foo[bar"] wouldn't work.

Changed March 04, 2010 01:38AM UTC by scottgonzalez comment:6

owner: → scott.gonzalez
status: newaccepted

Changed March 04, 2010 02:01AM UTC by scottgonzalez comment:7

resolution: → fixed
status: acceptedclosed

Fixed in r3869. I ended up using quotes because they do work even for unmatched brackets, despite what John said :-P

Changed January 01, 2011 01:58PM UTC by xebrix comment:8

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+"']"