this is my view:
@bulk_objects.each do |bulk_warehouse|
bulk_error = @wh_errors[:"bulk_warehouse#{@count}"] if @wh_errors
-%>
<tr class="<%= cycle("odd", "even") %>">
<%= hidden_field_tag("bulk_warehouse_id#{@count}",bulk_warehouse.id) %>
<td><%= text_field_tag("bulk_warehouse_asset#{@count}", bulk_warehouse.asset, :disabled => true)%></td>
<td><%= text_field_tag("bulk_warehouse_serial#{@count}", bulk_warehouse.serial, :disabled => true) %></td>
<td><%= check_box_tag "enable_record#{@count}",1,false,{:onclick => "bulk_warehouse_asset#{@count}.disabled =
bulk_warehouse_serial#{@count}.disabled =
!this.checked;"}%></td>
<td class="last">
<%= link_to "#{t("web-app-theme.delete", :default => "Delete")}", bulk_warehouse_path(bulk_warehouse), :method => :delete, :confirm => "#{t("web-app-theme.confirm", :default => "Are you sure?")}" %>
</td>
</tr>
</div>
<% @count = @count +1 %>
<% end -%>
</table>
<div class="actions-bar wat-cf">
<div class="actions">
</div>
..
and this is my controller:
@bulk_objects = BulkWarehouse.all
@count= @bulk_objects.count
Now I would add in my view a “Select all” checkbox that when you click on it enables all other “enable_record#{@count}” checkbox. I know that this thing should be done using Ajax and Jquery but I don’t know how. Anyone can help me?
Thank you ll
You can use button_to_function to create a button that will check/uncheck all the boxes on the form.
Place this code in your view, where you want your check/uncheck button to go. When the button is clicked, it will run the toggleChecked javascript function.
Place your javascript code at the bottom of your view.
The function also can be put into the respective .js file in assets/javascripts.
That should get you up and running.
————— UPDATE ——————
Button_to_function is now deprecated. I recommend handling this using an HTML5 button and jQuery.
View code for your button:
Javascript: