Fix: Wrap array-of-objects functions in window check and move outside IIFE

Ensure functions are available globally by wrapping them in a window check
and ensuring they're defined outside any IIFE scope. Also fix internal
function calls to use window.updateArrayObjectData for consistency.
This commit is contained in:
Chuck
2026-01-05 14:16:52 -05:00
parent 2993e67eb3
commit b38027d7ad

View File

@@ -3439,6 +3439,8 @@ window.updateKeyValuePairData = function(fieldId, fullKey) {
}; };
// Functions to handle array-of-objects // Functions to handle array-of-objects
// Define these at the top level (outside any IIFE) to ensure they're always available
if (typeof window !== 'undefined') {
window.addArrayObjectItem = function(fieldId, fullKey, maxItems) { window.addArrayObjectItem = function(fieldId, fullKey, maxItems) {
const itemsContainer = document.getElementById(fieldId + '_items'); const itemsContainer = document.getElementById(fieldId + '_items');
const hiddenInput = document.getElementById(fieldId + '_data'); const hiddenInput = document.getElementById(fieldId + '_data');
@@ -3472,7 +3474,7 @@ window.addArrayObjectItem = function(fieldId, fullKey, maxItems) {
const newIndex = currentItems.length; const newIndex = currentItems.length;
const itemHtml = renderArrayObjectItem(fieldId, fullKey, itemsSchema.properties, {}, newIndex, itemsSchema); const itemHtml = renderArrayObjectItem(fieldId, fullKey, itemsSchema.properties, {}, newIndex, itemsSchema);
itemsContainer.insertAdjacentHTML('beforeend', itemHtml); itemsContainer.insertAdjacentHTML('beforeend', itemHtml);
updateArrayObjectData(fieldId); window.updateArrayObjectData(fieldId);
// Update add button state // Update add button state
const addButton = itemsContainer.nextElementSibling; const addButton = itemsContainer.nextElementSibling;
@@ -3512,7 +3514,7 @@ window.removeArrayObjectItem = function(fieldId, index) {
} }
}); });
}); });
updateArrayObjectData(fieldId); window.updateArrayObjectData(fieldId);
// Update add button state // Update add button state
const addButton = itemsContainer.nextElementSibling; const addButton = itemsContainer.nextElementSibling;
@@ -3576,14 +3578,15 @@ window.handleArrayObjectFileUpload = function(event, fieldId, itemIndex, propKey
// TODO: Implement file upload handling for array object items // TODO: Implement file upload handling for array object items
// This is a placeholder - file upload in nested objects needs special handling // This is a placeholder - file upload in nested objects needs special handling
console.log('File upload for array object item:', { fieldId, itemIndex, propKey, pluginId }); console.log('File upload for array object item:', { fieldId, itemIndex, propKey, pluginId });
updateArrayObjectData(fieldId); window.updateArrayObjectData(fieldId);
}; };
window.removeArrayObjectFile = function(fieldId, itemIndex, propKey) { window.removeArrayObjectFile = function(fieldId, itemIndex, propKey) {
// TODO: Implement file removal for array object items // TODO: Implement file removal for array object items
console.log('File removal for array object item:', { fieldId, itemIndex, propKey }); console.log('File removal for array object item:', { fieldId, itemIndex, propKey });
updateArrayObjectData(fieldId); window.updateArrayObjectData(fieldId);
}; };
}
// Function to toggle nested sections // Function to toggle nested sections
window.toggleNestedSection = function(sectionId, event) { window.toggleNestedSection = function(sectionId, event) {