Simple check_box

Hello,

I’m trying create a simple check_box that if checked include a
hidden_field, but I haven’t success.

Something like this:


<%= check_box_tag(:patrono, value = “1”, checked = false, options =
{}) %>
<%= f.label “Patrono” %>
<% if :patrono.checked == true %>
<%= f.hidden_field “tipo_componente_ids][”, { :id =>
“tipo_componente_ids”, :value => @patrono.id } %>
<% end %>

Thanks for help!

Eric,

You have to write javascript function within the check_box_tag in order
to verify whether the checkbox is checked or not and then enable the
hidden field if it is checked.

Saravanan K
http://bit.ly/9NpP7e

hi,

use jQuery and then

= f.hidden_field_tag “hidden_field”, “value”, { :id => “hidden_field”}
= f.check_box_tag “name”, 1,false, {:id => “my_checkbox”}

jQuery(’#my_checkbox’).bind(‘click’, function() {
jQuery(’#hidden_field’).attr(‘disabled’,
!jQuery(this).attr(‘checked’));
}

when field is disabled, it’s not taken into account when form is sent

PS: if not using jQuery, it’s simple to do with DOM too, just add
:onClick=‘disableField()’ to the checkbox and
function disableField() {
document.getElementById(‘hidden_field’).disabled =
!document.getElementById(‘my_checkbox’).checked;
return false;
}

tom

On May 19, 2011, at 14:15 , Eric M. wrote:

<% if :patrono.checked == true %>

You received this message because you are subscribed to the Google G. “Ruby
on Rails: Talk” group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


Maxwell Render CZ
Autorizovany distributor Maxwell renderu pro Ceskou republiku

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs