mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-11 13:23:00 +00:00
fix: Expose getSchemaProperty, disable upload widget, handle bracket notation arrays
Multiple fixes for array-of-objects and form processing: 1. Expose getSchemaProperty to window (plugins_manager.js): - getSchemaProperty was defined inside IIFE but needed by global functions - Added window.getSchemaProperty = getSchemaProperty before IIFE closes - Updated window.addArrayObjectItem to use window.getSchemaProperty - Fixes ReferenceError when dynamically adding array items 2. Disable upload widget for custom feeds (plugin_config.html): - File input and Upload button were still active but should be disabled - Removed onchange/onclick handlers, added disabled and aria-disabled - Added visible disabled styling and tooltip - Existing logos continue to display but uploads are prevented - Matches PR objectives to disable upload until fully implemented 3. Handle bracket notation array fields (api_v3.py): - checkbox-group uses name="field_name[]" which sends multiple values - request.form.to_dict() collapses duplicate keys (only keeps last value) - Added handling to detect fields ending with "[]" before to_dict() - Use request.form.getlist() to get all values, combine as comma-separated - Processed before existing array index field handling - Fixes checkbox-group losing all but last selected value
This commit is contained in:
@@ -3335,7 +3335,33 @@ def save_plugin_config():
|
|||||||
# Form fields can use dot notation for nested values (e.g., "transition.type")
|
# Form fields can use dot notation for nested values (e.g., "transition.type")
|
||||||
form_data = request.form.to_dict()
|
form_data = request.form.to_dict()
|
||||||
|
|
||||||
# First pass: detect and combine array index fields (e.g., "text_color.0", "text_color.1" -> "text_color" as array)
|
# First pass: handle bracket notation array fields (e.g., "field_name[]" from checkbox-group)
|
||||||
|
# These fields use getlist() to preserve all values, then replace in form_data
|
||||||
|
bracket_array_fields = {} # Maps base field path to list of values
|
||||||
|
for key in request.form.keys():
|
||||||
|
# Check if key ends with "[]" (bracket notation for array fields)
|
||||||
|
if key.endswith('[]'):
|
||||||
|
base_path = key[:-2] # Remove "[]" suffix
|
||||||
|
values = request.form.getlist(key)
|
||||||
|
if values:
|
||||||
|
bracket_array_fields[base_path] = values
|
||||||
|
# Remove the bracket notation key from form_data if present
|
||||||
|
if key in form_data:
|
||||||
|
del form_data[key]
|
||||||
|
|
||||||
|
# Process bracket notation fields and add to form_data as comma-separated strings
|
||||||
|
for base_path, values in bracket_array_fields.items():
|
||||||
|
# Get schema property to verify it's an array
|
||||||
|
base_prop = _get_schema_property(schema, base_path)
|
||||||
|
if base_prop and base_prop.get('type') == 'array':
|
||||||
|
# Combine values into comma-separated string for consistent parsing
|
||||||
|
combined_value = ', '.join(str(v) for v in values if v)
|
||||||
|
form_data[base_path] = combined_value
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
logger.debug(f"Processed bracket notation array field {base_path}: {values} -> {combined_value}")
|
||||||
|
|
||||||
|
# Second pass: detect and combine array index fields (e.g., "text_color.0", "text_color.1" -> "text_color" as array)
|
||||||
# This handles cases where forms send array fields as indexed inputs
|
# This handles cases where forms send array fields as indexed inputs
|
||||||
array_fields = {} # Maps base field path to list of (index, value) tuples
|
array_fields = {} # Maps base field path to list of (index, value) tuples
|
||||||
processed_keys = set()
|
processed_keys = set()
|
||||||
|
|||||||
@@ -6467,8 +6467,9 @@ window.updateImageScheduleDay = function(fieldId, imageId, imageIdx, day) {
|
|||||||
window.updateImageList(fieldId, currentImages);
|
window.updateImageList(fieldId, currentImages);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expose renderArrayObjectItem to window for use by window.addArrayObjectItem
|
// Expose renderArrayObjectItem and getSchemaProperty to window for use by global functions
|
||||||
window.renderArrayObjectItem = renderArrayObjectItem;
|
window.renderArrayObjectItem = renderArrayObjectItem;
|
||||||
|
window.getSchemaProperty = getSchemaProperty;
|
||||||
|
|
||||||
})(); // End IIFE
|
})(); // End IIFE
|
||||||
|
|
||||||
@@ -6491,7 +6492,7 @@ if (typeof window !== 'undefined') {
|
|||||||
if (!schema) return;
|
if (!schema) return;
|
||||||
|
|
||||||
// Use getSchemaProperty to properly handle nested schemas (e.g., news.custom_feeds)
|
// Use getSchemaProperty to properly handle nested schemas (e.g., news.custom_feeds)
|
||||||
const arraySchema = getSchemaProperty(schema, fullKey);
|
const arraySchema = window.getSchemaProperty(schema, fullKey);
|
||||||
if (!arraySchema || arraySchema.type !== 'array' || !arraySchema.items) {
|
if (!arraySchema || arraySchema.type !== 'array' || !arraySchema.items) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -232,10 +232,13 @@
|
|||||||
id="{{ field_id }}_logo_{{ item_index }}"
|
id="{{ field_id }}_logo_{{ item_index }}"
|
||||||
accept="image/png,image/jpeg,image/bmp,image/gif"
|
accept="image/png,image/jpeg,image/bmp,image/gif"
|
||||||
style="display: none;"
|
style="display: none;"
|
||||||
onchange="handleCustomFeedLogoUpload(event, '{{ field_id }}', {{ item_index }}, '{{ plugin_id }}', '{{ full_key }}')">
|
disabled
|
||||||
|
aria-disabled="true">
|
||||||
<button type="button"
|
<button type="button"
|
||||||
onclick="document.getElementById('{{ field_id }}_logo_{{ item_index }}').click()"
|
disabled
|
||||||
class="px-2 py-1 text-xs bg-gray-200 hover:bg-gray-300 rounded">
|
aria-disabled="true"
|
||||||
|
class="px-2 py-1 text-xs bg-gray-200 text-gray-400 rounded cursor-not-allowed opacity-50"
|
||||||
|
title="Logo upload for custom feeds is not yet implemented">
|
||||||
<i class="fas fa-upload mr-1"></i> Upload
|
<i class="fas fa-upload mr-1"></i> Upload
|
||||||
</button>
|
</button>
|
||||||
{% if logo_path %}
|
{% if logo_path %}
|
||||||
|
|||||||
Reference in New Issue
Block a user