Add class attribute to :collection/Association <option>s?

797 views
Skip to first unread message

John Rees

unread,
Mar 15, 2011, 10:32:49 AM3/15/11
to SimpleForm
I'm hoping to do chained select boxes with this jquery plugin
http://www.appelsiini.net/2010/jquery-chained-selects

It works by matching the option class attribute from the chained
select input with the option value attribute from the original select
input.

Abridged example from the site -

<select id="mark">
<option value="bmw">BMW</option>
<option value="audi">Audi</option>
</select>
<select id="series">
<option value="series-3" class="bmw">3 series</option>
<option value="a3" class="audi">A3</option>
<option value="a4" class="audi">A4</option>
</select>

So I was wondering if it is there any simple ruby magic that could
pass a custom class attribute into a :collection?

Thanks!

Carlos Antonio da Silva

unread,
Mar 15, 2011, 10:55:21 AM3/15/11
to plataformate...@googlegroups.com, John Rees
There is nothing specific, although we had some attempts to add it to SimpleForm: https://github.com/plataformatec/simple_form/issues#issue/188

The problem, as we've discussed there, is that collection_select is a Rails form helper method, which creates the options internally. To make this work we'd have to recreate the entire feature.

You can try out a patch if you want, I'd be glad to help.
--
At.
Carlos A. da Silva

John Rees

unread,
Mar 15, 2011, 11:02:10 AM3/15/11
to SimpleForm
Oh right, thanks for the reply. Also sorry, I thought I had properly
searched through previous issues for anything similar, clearly not!

On Mar 15, 2:55 pm, Carlos Antonio da Silva
Reply all
Reply to author
Forward
0 new messages