Rails toggling closest submit button in a form with radio buttons

Posted by Timothy on Stack Overflow See other posts from Stack Overflow or by Timothy
Published on 2010-05-28T18:57:54Z Indexed on 2010/05/28 19:02 UTC
Read the original article Hit count: 153

Filed under:

I have a bunch of forms listed in Rails like such

<% parent.children.some_named_scope.each do |child| %>
  <% form_for :parent, parent do |f| %>
      <% current_value = child.column_to_set %>
      <% child.possible_values_for_column_to_set.each do |value| %>
        <% f.fields_for :children, child, :child_index => child.id.to_s do |child_form| %>
          <%= child_form.label :column_to_set, value.to_s.titleize, :value => value %>
          <%= child_form.radio_button, :column_to_set, value, :type => 'radio' %>
        <% end %>
      <% end %>
    <%= f.submit "Submit", :disabled => true %>
  <% end %>
<% end %>

How do I set the submit button's disabled to false, dynamically, when it is not current_value and set it to true when it is while the user clicks radio buttons?

© Stack Overflow or respective owner

Related posts about ruby-on-rails