Extract function in "check all/none" JavaScript file

This commit is contained in:
Javi Martín
2024-04-12 03:32:43 +02:00
parent 15ca47caed
commit a911b0dec7

View File

@@ -3,15 +3,14 @@
App.CheckAllNone = { App.CheckAllNone = {
initialize: function() { initialize: function() {
$("[data-check-all]").on("click", function() { $("[data-check-all]").on("click", function() {
var target_name; App.CheckAllNone.associated_fields($(this), "check-all").prop("checked", true);
target_name = $(this).data("check-all");
$("[name='" + target_name + "']").prop("checked", true);
}); });
$("[data-check-none]").on("click", function() { $("[data-check-none]").on("click", function() {
var target_name; App.CheckAllNone.associated_fields($(this), "check-none").prop("checked", false);
target_name = $(this).data("check-none");
$("[name='" + target_name + "']").prop("checked", false);
}); });
},
associated_fields: function(element, data_attribute) {
return $("[name='" + element.data(data_attribute) + "']");
} }
}; };
}).call(this); }).call(this);