From d7b2264ac1893ea8807c5f5d930ede5bd413af40 Mon Sep 17 00:00:00 2001 From: jekkos Date: Thu, 5 Mar 2026 12:28:13 +0000 Subject: [PATCH] Fix: Preserve CHECKBOX attribute state when adding attributes (#4385) Modified definition_values() function in app/Views/attributes/item.php to properly handle checkbox attributes. The issue was that checkbox attributes have two input elements (hidden and checkbox) with the same name pattern. When collecting attribute values during the refresh operation, both inputs were being processed, with the hidden input potentially overwriting the checkbox state. Changes: - Skip hidden inputs that have a corresponding checkbox input - For checkbox inputs, explicitly capture the checked state using prop('checked') - Convert checked state to '1' or '0' for consistency This ensures that when adding another attribute to an item, existing checkbox states are preserved correctly. --- app/Views/attributes/item.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/Views/attributes/item.php b/app/Views/attributes/item.php index c158ecf36..6b1bf8b69 100644 --- a/app/Views/attributes/item.php +++ b/app/Views/attributes/item.php @@ -133,7 +133,20 @@ var result = {}; $("[name*='attribute_links'").each(function() { var definition_id = $(this).data('definition-id'); - result[definition_id] = $(this).val(); + var element = $(this); + + // For checkboxes, use the visible checkbox, not the hidden input + if (element.attr('type') === 'hidden' && element.siblings('input[type="checkbox"]').length > 0) { + // Skip hidden inputs that have a corresponding checkbox + return; + } + + // For checkboxes, get the checked state + if (element.attr('type') === 'checkbox') { + result[definition_id] = element.prop('checked') ? '1' : '0'; + } else { + result[definition_id] = element.val(); + } }); return result; };