Checkbox inline for different db fields

54 views
Skip to first unread message

Fernando Shayani

unread,
Apr 13, 2012, 9:00:01 AM4/13/12
to SimpleForm
Hi all. I posted this question in the GitHut site but I'll also post
here. Any help will be useful :)

I'm having some trouble to create a group of checkboxes with
simple_form and bootstrap.

I have 3 fields in the database that are booleans: option1, option2
and option3. I need to create a checkbox group inline like this:

SELECT YOUR OPTIONS: [ ] Option 1 [ ] Option 2 [ ] Option 3
Rails is expecting to send the fields as independent fields, like
"tablename[option1]" , "tablename[option2]" and "tablename[option3]".

If I use the

f.input :option, :collection => [[true, '1'] ,[true, '2'],[true,
'3']], :as => :check_boxes

, the html markup will be messed up.

I'm looking for a way so the markup will something like:

<input name="tablename[option1]" type="hidden" value="0">
<input name="tablename[option2]" type="hidden" value="0">
<input name="tablename[option3]" type="hidden" value="0">

If I just use the

f.input :option1
f.input :option2
f.input :option3

the checkboxes will be vertical and will not be "grouped".

Any ideas?

Carlos Antonio da Silva

unread,
Apr 21, 2012, 6:29:09 PM4/21/12
to plataformate...@googlegroups.com
Hey Fernando,

have you tried the solutions we've discussing in the issue? Did it work? 
I'll link here for future reference: https://github.com/plataformatec/simple_form/issues/538

If it is not working for you yet, we can try to figure out another solution.

-- 
At.
Carlos Antonio

Fernando Shayani

unread,
Apr 24, 2012, 2:59:05 PM4/24/12
to plataformate...@googlegroups.com
Hi Carlos,

I tried the solution, but didn't work. The output was all messy.

Carlos Antonio da Silva

unread,
Apr 24, 2012, 3:17:26 PM4/24/12
to plataformate...@googlegroups.com
That's weird.. perhaps you could try adding some example to the https://github.com/rafaelfranca/simple_form-bootstrap app, so we can play with and see were we go?

-- 
At.
Carlos Antonio

Reply all
Reply to author
Forward
0 new messages