refactor: scope checkbox selection to dialog and extract reusable function

- Scope checkbox selector to .column-selector-list to prevent selecting checkboxes outside the dialog
- Refactor Select All and Unselect All into reusable toggle_all_checkboxes function
- Reduce code duplication and improve maintainability
This commit is contained in:
circlecrystalin 2026-01-20 18:14:30 +01:00
parent b3b85b9090
commit 65dbc16948

View file

@ -704,31 +704,36 @@ frappe.PrintFormatBuilder = class PrintFormatBuilder {
update_column_count_message();
});
// Select All functionality
$body.on("click", ".select-all-btn", function () {
$body.find("input[type='checkbox']").each(function () {
if (!$(this).prop("checked")) {
$(this).prop("checked", true);
const fieldname = $(this).attr("data-fieldname");
// Toggle all checkboxes in column selector
const toggle_all_checkboxes = function (should_check, should_clear_value) {
// Scope to column selector list checkboxes only
$body.find(".column-selector-list input[type='checkbox'][data-fieldname]").each(function () {
const $checkbox = $(this);
const is_checked = $checkbox.prop("checked");
// Only process checkboxes that need to be changed
if ((should_check && !is_checked) || (!should_check && is_checked)) {
$checkbox.prop("checked", should_check);
const fieldname = $checkbox.attr("data-fieldname");
const input = get_width_input(fieldname);
input.prop("disabled", false);
input.prop("disabled", !should_check);
if (should_clear_value) {
input.val("");
}
}
});
update_column_count_message();
};
// Select All functionality
$body.on("click", ".select-all-btn", function () {
toggle_all_checkboxes(true, false);
});
// Unselect All functionality
$body.on("click", ".unselect-all-btn", function () {
$body.find("input[type='checkbox']").each(function () {
if ($(this).prop("checked")) {
$(this).prop("checked", false);
const fieldname = $(this).attr("data-fieldname");
const input = get_width_input(fieldname);
input.prop("disabled", true);
input.val("");
}
});
update_column_count_message();
toggle_all_checkboxes(false, true);
});
d.show();