Topic: a complex form with checkboxes and ajax...

I need to build a form with various fields that are checkboxes and each of which if checked reveal other text fields for example. How can ii do that? do i have to use ajax? If so is there a way to make an ajax request when a particular checkbox is checked to add other related fields on the fly?

Re: a complex form with checkboxes and ajax...

Hello,

Not really necessary to use ajax for that, only javascript is fine.

<%=check_box_tag :box1, :oncheck => "$('hidden-fields').style.display = '';" # or onclick maybe, look it up :-)
<div id="hidden-fields" style="display:none;">
secret field:
<%=text_field_tag :hidden_thing %>
</div>

Or something similar...

Stijn

Re: a complex form with checkboxes and ajax...

ok i will try that....and to split a big forum (same model but different sections) maybe in different pages?

Re: a complex form with checkboxes and ajax...

Couldn't get this to work skyblaze.. anyone have any luck with this?

Re: a complex form with checkboxes and ajax...

i mean the best way.....i think of it as passing values between pages over which there are the various form parts and then at the last page( form part) there is the model validation....is there a better way?

Re: a complex form with checkboxes and ajax...

for the multipage form i searched on this forum and found a solution that uses an opensource javascript library that splits the form in html tabs but in reality it is one page from a rails perspective. Then I've tried your checkbox javascript solution and it works fine but now i have to do also the inverse....i mean, i have to also hide those fields when the checkbox is unchecked. I searched also on this but didn't find some related javascript/dom event.

Re: a complex form with checkboxes and ajax...

I couldn't get this to work but you could use .toggle instead of .display.

Re: a complex form with checkboxes and ajax...

malkomalko wrote:

I couldn't get this to work but you could use .toggle instead of .display.

an example?