Checkbox_tag outside a form?

Is it possible to use checkbox_tag outside a form? I’ve put it in a
view and it renders but I get nothing back in the params hash. Is there
a way to get the value? Like maybe with some JS onsubmit to populate
the params hash myself?

Thanks,
Bill

Bill W. wrote:

Is it possible to use checkbox_tag outside a form? I’ve put it in a view and it renders but I get nothing back in the params hash. Is there a way to get the value? Like maybe with some JS onsubmit to populate the params hash myself?

Thanks,
Bill

I think the easiest solution is to spread our your tags so
that the checkbox falls between them. If there’s just one form on the
page, I don’t think there’s anything particularly wrong with

although that’s usually a bit extreme.

If, for whatever reason, that’s not practical (maybe due to different
partials and layouts breaking things up too much), then you could place
a hidden tag in the form, and use an onChange event at the checkbox to
update the value of the hidden tag. Then, the value of the hidden tag is
what will be available in the params hash on the server. That’s a bit
more complicated, but not too difficult if you’re familiar with
javascript and onChange events. Of course, if the user has javascript
disabled, then this won’t work at all. So, I’d recommend just finding a
way to spread out those tags.

Hi Jonathan,

Jonathan M. wrote:

I think the easiest solution is to spread our your

tags so that the checkbox falls between them. If there's just one form on the page,

That’s the problem. This posting was actually a follow-on to an earlier
one
where I thought the solution to my problem could be solved by using
checkbox_tag outside a form. Doesn’t look like it now. I’ve included
the
earlier post below just in case you have any ideas.

Thanks much,
Bill


----- Original Message -----
From: Bill W.
To: [email protected]
Sent: Tuesday, June 20, 2006 9:03 AM
Subject: [Rails] Soliciting suggestions - Form within a Form

Greetings!

I could use some suggestions on how to proceed from where I am to
where I
want to go.

I’m working on an app that collects info from the visitor and saves it
to
a file. The file can later be read in for update. To collect the info,
the
app presents a form with a set of checkboxes. The state of the
checkboxes
at initial presentation is controlled by a summary record that is
created /
populated when the file is read in for updating. The record contains
fields
for each of the checkboxes with the value = ‘y’ or ‘n’. In addition to
a
set of ‘standard’ selections, the form also has a checkbox labeled
‘Other’.

Currently, when the form is submitted, individual records are created
for
each checked checkbox for the standard selections. If the ‘Other’
checkbox
is checked, after records are created for the ‘standard’ items, I render
a
second page with a form that allows them to enter one or more other
items.
Individual records for those items are created via RJS as the items are
entered.

I’d like to allow the addition of the ‘Other’ items on the same page
as
the standard checkbox selections. If the visitor checks the ‘Other’
checkbox, I want to replace the checkbox with the partial that’s
currently
being rendered on the second page. I can do that by putting the ‘Other’
checkbox in a

and doing an RJS ‘replace_html’.

Unfortunately RoR doesn’t support forms within forms. Clicking the
‘Submit’ button on the sub-form submits the entire form. So that
doesn’t
work for me.

I’m considering eliminating the top level form and just using a
‘button_to’ to pass the entered info from the view back to the
controller.
Pro: The ‘Other’ form processing works fine
Con: Since they’re not contained within a form anymore, the checkboxes
aren’t serialized and passed to the controller via the params hash.

I believe I can use ‘checkbox_tag’ instead of ‘checkbox’ to get the
values
back to the controller, but that leaves me with the chore of
initializing
them for presentation from the values in the summary record. Overall,
this
path feels non-Railish.

Any suggestions would be greatly appreciated.

Thanks,
Bill

hi there,
it´s not really that ror doesn´t support forms in forms… it´s the
browsers that don´t.
we had a problem a bit like yours.
what we did is just place the “subform” in a

that was outside the
other form and just positioned it “inside” the other form later.
that worked.
kind regards,
alexander