mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-03-11 19:50:25 -04:00
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.
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user