Checkboxes and its label's for attribute

26 views
Skip to first unread message

Andy Shen

unread,
Jun 23, 2011, 6:58:36 AM6/23/11
to SimpleForm
Hi,

I am on a page that renders forms for a number of account models.
Each account has a boolean column called 'active'.
So there are multiple checkboxes and their label all have the same
"for" attribute which means clicking the label is only going to check
the first checkbox instead of the corresponding input next to the
label.

My question is what would you recommend such that clicking the label
will tick the expected checkbox input?

Thanks,
Andy

Carlos Antonio

unread,
Jun 23, 2011, 9:28:57 AM6/23/11
to plataformate...@googlegroups.com
This probably means that all your checkboxes have the same id. Check you html output to see that.

What you can do is add a default for/id to your label/input by setting the :id in the input_html option, like this:

    f.input :active, :input_html => { :id => "active_x" }

Where x would probably be something that represents the given checkbox, like a numeric index.

-- 
At.
Carlos A. da Silva

Andy Shen

unread,
Jun 23, 2011, 5:58:21 PM6/23/11
to SimpleForm
Thanks, that worked as expected now.

On Jun 23, 11:28 pm, Carlos Antonio <carlosantoniodasi...@gmail.com>
wrote:

Mark Pitsilos

unread,
Jun 5, 2015, 5:24:20 AM6/5/15
to plataformate...@googlegroups.com
Hello,

In case the check box is nested within the label, normally no for attribute should be necessary.

Is there a way to disable rendering the for attribute for check boxes?

Thank you,

Mark
Reply all
Reply to author
Forward
0 new messages