Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
37 lines (30 sloc) 1.11 KB
<h1>Mass Edit</h1>
<%= form_for @book, :url => mass_update_books_path, :method => :put, :builder => MassFormBuilder do |f| %>
Editing the following:
<ul>
<% @books.each do |book| %>
<li><%= book.title %><%= hidden_field_tag "ids[]", book.id %></li>
<% end %>
</ul>
<%= render 'form_fields', :f => f %>
<% end %>
<script>
$('input[type="checkbox"][name="_null"]').change(function() {
var checkbox = $(this);
var field_name = checkbox.val();
var field = $('[type!="hidden"][id="' + field_name + '"]');
var hidden_field = $('input[type="hidden"][id="' + field_name + '"]');
if (checkbox.prop('checked')) {
field.attr("disabled", "disabled");
hidden_field.removeAttr("disabled");
} else {
field.removeAttr("disabled");
hidden_field.attr("disabled", "disabled");
}
});
$('#new_book').submit(function() {
// Disable any empty, non-hidden, enabled fields before submitting
fields = $('#new_book :input[type!="hidden"][disabled!="disabled"]').filter(function() { return $(this).val() == ""; });
fields.attr("disabled", "disabled");
});
</script>