mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-11 05:13:01 +00:00
fix: Use JSON encoding for bracket-notation arrays and add sentinel for clearing
Fix bracket-notation array handling to prevent data loss: 1. Use JSON encoding instead of comma-join (lines 3358-3359): - Comma-join breaks if option values contain commas - Switch to json.dumps() to encode array values as JSON strings - _parse_form_value_with_schema() already handles JSON arrays correctly - Preserves values with commas, special characters, etc. 2. Add sentinel hidden input for clearing arrays: - Add hidden input with name="field[]" value="" in checkbox-group template - Ensures field is always submitted, even when all checkboxes unchecked - Backend filters out sentinel empty strings to detect empty array - Allows users to clear array to [] by unchecking all options 3. Update backend to handle sentinel: - Filter out sentinel empty strings from bracket notation values - Empty array (all unchecked) is represented as "[]" JSON string - Properly handles both sentinel-only (empty array) and sentinel+values cases This fixes data loss when: - Option values contain commas (comma-join corruption) - All checkboxes are unchecked (field omitted from form, can't clear to [])
This commit is contained in:
@@ -3034,6 +3034,9 @@ function generateFieldHtml(key, prop, value, prefix = '') {
|
||||
html += `</div>`;
|
||||
// Hidden input to store selected values as JSON array (like array-of-objects pattern)
|
||||
html += `<input type="hidden" id="${fieldId}_data" name="${fullKey}_data" value='${JSON.stringify(arrayValue).replace(/'/g, "'")}'>`;
|
||||
// Sentinel hidden input with bracket notation to allow clearing array to [] when all unchecked
|
||||
// This ensures the field is always submitted, even when all checkboxes are unchecked
|
||||
html += `<input type="hidden" name="${fullKey}[]" value="">`;
|
||||
} else if (xWidgetValue === 'custom-feeds' || xWidgetValue2 === 'custom-feeds') {
|
||||
// Custom feeds widget - check schema validation first
|
||||
const itemsSchema = prop.items || {};
|
||||
|
||||
Reference in New Issue
Block a user