We need to add a hidden field for each group of check boxes, so if we don't check anything, the hidden field is sent to the server, indicating nothing was selected. Without the hidden field, the server will not know anything has been done to the check boxes. The easiest way to do it is using `collection_check_boxes`, which also adds labels to every check box.
34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
(function() {
|
|
"use strict";
|
|
App.BudgetEditAssociations = {
|
|
initialize: function() {
|
|
$(".js-budget-users-list [type='checkbox']").on({
|
|
change: function() {
|
|
var admin_count, tracker_count, valuator_count;
|
|
|
|
admin_count = $("#administrators_list :checked").length;
|
|
valuator_count = $("#valuators_list :checked").length;
|
|
tracker_count = $("#trackers_list :checked").length;
|
|
|
|
App.I18n.set_pluralize($(".js-budget-show-administrators-list"), admin_count);
|
|
App.I18n.set_pluralize($(".js-budget-show-valuators-list"), valuator_count);
|
|
App.I18n.set_pluralize($(".js-budget-show-trackers-list"), tracker_count);
|
|
}
|
|
});
|
|
$(".js-budget-show-users-list").on({
|
|
click: function(e) {
|
|
var div_id;
|
|
|
|
e.preventDefault();
|
|
div_id = $(this).data().toggle;
|
|
$(".js-budget-users-list").each(function() {
|
|
if (this.id !== div_id && !$(this).hasClass("is-hidden")) {
|
|
$(this).addClass("is-hidden");
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
};
|
|
}).call(this);
|