Topic: help with checkbox click

Hi,
I would like to know how i can do that? by jquery? helper?
I would like to have a checkbox button, when we click on it in form, i show a nested fields_from partial.

I use link_to_add and link_to_remove from nested_form gem.

I would like to have the same thing but with checkbox .

In my models, i have checkbox set to boolean.
if checkbox is unchec, remove everything associed to this models.

If the checkbox is checked, i would like to add the first fields_for render.

i have tryed a simple : show(), hide() but my nested model doesn't take the updated.

Do you have an idea how i can do that?
thanks.

Re: help with checkbox click

Given a form like this:

<form>
  <ul>
    <li>
      <label for="show_or_hide_secret_fields">Show secret fields</label>
      <input type="checkbox" id="show_or_hide_secret_fields" />
    </li>
  </ul>
  <ul id="secret_fields" style="display: none;">
    <li><input type="text" name="foo" /></li>
  </ul>
</form>

You'd just do (with jQuery for example):

$(function() {
  $('#show_or_hide_secret_fields').click(function() {
    $('#secret_fields').toggle();
  });
});

-patrick

Last edited by patrick99e99 (2011-08-07 18:20:03)

Re: help with checkbox click

Thanks there is no rails fonction to create that?