From 97c684aad26e1616021be433b9f599b042153ba1 Mon Sep 17 00:00:00 2001 From: Chuck Date: Thu, 8 Jan 2026 13:47:05 -0500 Subject: [PATCH] fix: Remove duplicate submit handler to prevent double POSTs Remove document-level submit listener that conflicts with handlePluginConfigSubmit, causing duplicate form submissions with divergent payloads. Problem: - handlePluginConfigSubmit correctly parses JSON from _data fields and maps to flatConfig[baseKey] for patternProperties and array-of-objects - Document-level listener (line 5368) builds its own config without understanding _data convention and posts independently via savePluginConfiguration - Every submit now sends two POSTs with divergent payloads: - First POST: Correct structure with parsed _data fields - Second POST: Incorrect structure with raw _data fields, missing structure - Arrays-of-objects and patternProperties saved incorrectly in second request Solution: - Remove document-level submit listener for #plugin-config-form - Rely solely on handlePluginConfigSubmit which is already attached to the form - handlePluginConfigSubmit properly handles all form-to-config conversion including: - _data field parsing (JSON from hidden fields) - Type-aware conversion using schema - Dot notation to nested object conversion - PatternProperties and array-of-objects support Note: savePluginConfiguration function remains for use by JSON editor saves --- web_interface/static/v3/plugins_manager.js | 42 ++-------------------- 1 file changed, 3 insertions(+), 39 deletions(-) diff --git a/web_interface/static/v3/plugins_manager.js b/web_interface/static/v3/plugins_manager.js index 7cf6337e..631a9c36 100644 --- a/web_interface/static/v3/plugins_manager.js +++ b/web_interface/static/v3/plugins_manager.js @@ -5364,45 +5364,9 @@ function showError(message) { `; } -// Plugin configuration form submission -document.addEventListener('submit', function(e) { - if (e.target.id === 'plugin-config-form') { - e.preventDefault(); - - const formData = new FormData(e.target); - const config = {}; - const schema = currentPluginConfig?.schema; - - // Convert form data to config object - // Note: 'enabled' is managed separately via the header toggle, not through this form - for (let [key, value] of formData.entries()) { - // Skip enabled - it's managed separately via the header toggle - if (key === 'enabled') continue; - - // Check if this field is an array type in the schema - if (schema?.properties?.[key]?.type === 'array') { - // Convert comma-separated string to array - const arrayValue = value.split(',').map(item => item.trim()).filter(item => item.length > 0); - config[key] = arrayValue; - console.log(`Array field ${key}: "${value}" -> `, arrayValue); - } else if (key === 'display_duration' || schema?.properties?.[key]?.type === 'integer') { - config[key] = parseInt(value); - } else if (schema?.properties?.[key]?.type === 'number') { - config[key] = parseFloat(value); - } else if (schema?.properties?.[key]?.type === 'boolean') { - config[key] = value === 'true' || value === true; - } else { - config[key] = value; - } - } - - console.log('Final config to save:', config); - console.log('Schema loaded:', schema ? 'Yes' : 'No'); - - // Save the configuration - savePluginConfiguration(currentPluginConfig.pluginId, config); - } -}); +// Plugin configuration form submission is handled by handlePluginConfigSubmit +// which is attached directly to the form. The document-level listener has been removed +// to avoid duplicate submissions and to ensure proper handling of _data fields. function savePluginConfiguration(pluginId, config) { // Update the plugin configuration in the backend