diff --git a/frappe/printing/page/print_format_builder/print_format_builder.js b/frappe/printing/page/print_format_builder/print_format_builder.js index c651bc157c..eb91f44141 100644 --- a/frappe/printing/page/print_format_builder/print_format_builder.js +++ b/frappe/printing/page/print_format_builder/print_format_builder.js @@ -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();