- `;
-
+ // Display existing logo if present, but disable upload functionality
if (logoValue.path) {
html += `
-
-

+
+ `;
+ } else {
+ html += `
+
`;
}
@@ -6433,19 +6434,13 @@ if (typeof window !== 'undefined') {
const schema = (typeof currentPluginConfig !== 'undefined' && currentPluginConfig?.schema) || (typeof window.currentPluginConfig !== 'undefined' && window.currentPluginConfig?.schema);
if (!schema) return;
- // Navigate to the items schema
- const keys = fullKey.split('.');
- let itemsSchema = schema.properties;
- for (const key of keys) {
- if (itemsSchema && itemsSchema[key]) {
- itemsSchema = itemsSchema[key];
- if (itemsSchema.type === 'array' && itemsSchema.items) {
- itemsSchema = itemsSchema.items;
- break;
- }
- }
+ // Use getSchemaProperty to properly handle nested schemas (e.g., news.custom_feeds)
+ const arraySchema = getSchemaProperty(schema, fullKey);
+ if (!arraySchema || arraySchema.type !== 'array' || !arraySchema.items) {
+ return;
}
+ const itemsSchema = arraySchema.items;
if (!itemsSchema || !itemsSchema.properties) return;
const newIndex = currentItems.length;
@@ -6489,24 +6484,55 @@ if (typeof window !== 'undefined') {
if (item) {
item.remove();
// Re-index remaining items
+ // Use data-index for index storage - no need to encode index in onclick strings or IDs
const remainingItems = itemsContainer.querySelectorAll('.array-object-item');
remainingItems.forEach((itemEl, newIndex) => {
itemEl.setAttribute('data-index', newIndex);
- // Update all inputs within this item - need to update name/id attributes
+ // Update all inputs within this item - only update index in array bracket notation
itemEl.querySelectorAll('input, select, textarea').forEach(input => {
- const name = input.getAttribute('name') || input.id;
+ const name = input.getAttribute('name');
+ const id = input.id;
if (name) {
- // Update name/id attribute with new index
- const newName = name.replace(/\[\d+\]/, `[${newIndex}]`);
- if (input.getAttribute('name')) input.setAttribute('name', newName);
- if (input.id) input.id = input.id.replace(/\d+/, newIndex);
+ // Only replace index in bracket notation like [0], [1], etc.
+ // Match pattern: field_name[index] but not field_name123
+ const newName = name.replace(/\[(\d+)\]/, `[${newIndex}]`);
+ input.setAttribute('name', newName);
+ }
+ if (id) {
+ // Only update index in specific patterns like _item_0, _item_1
+ // Match pattern: _item_
but be careful not to break other numeric IDs
+ const newId = id.replace(/_item_(\d+)/, `_item_${newIndex}`);
+ input.id = newId;
}
});
- // Update button onclick attributes
+ // Update button onclick attributes - only update the index parameter
+ // Since we use data-index for tracking, we can compute index from closest('.array-object-item')
+ // For now, update onclick strings but be more careful with the regex
itemEl.querySelectorAll('button[onclick]').forEach(button => {
const onclick = button.getAttribute('onclick');
if (onclick) {
- button.setAttribute('onclick', onclick.replace(/\d+/, newIndex));
+ // Match patterns like:
+ // removeArrayObjectItem('fieldId', 0)
+ // handleArrayObjectFileUpload(event, 'fieldId', 0, 'propKey', 'pluginId')
+ // removeArrayObjectFile('fieldId', 0, 'propKey')
+ // Only replace the numeric index parameter (second or third argument depending on function)
+ let newOnclick = onclick;
+ // For removeArrayObjectItem('fieldId', index) - second param
+ newOnclick = newOnclick.replace(
+ /removeArrayObjectItem\s*\(\s*['"]([^'"]+)['"]\s*,\s*\d+\s*\)/g,
+ `removeArrayObjectItem('$1', ${newIndex})`
+ );
+ // For handleArrayObjectFileUpload(event, 'fieldId', index, ...) - third param
+ newOnclick = newOnclick.replace(
+ /handleArrayObjectFileUpload\s*\(\s*event\s*,\s*['"]([^'"]+)['"]\s*,\s*\d+\s*,/g,
+ `handleArrayObjectFileUpload(event, '$1', ${newIndex},`
+ );
+ // For removeArrayObjectFile('fieldId', index, ...) - second param
+ newOnclick = newOnclick.replace(
+ /removeArrayObjectFile\s*\(\s*['"]([^'"]+)['"]\s*,\s*\d+\s*,/g,
+ `removeArrayObjectFile('$1', ${newIndex},`
+ );
+ button.setAttribute('onclick', newOnclick);
}
});
});
@@ -6514,12 +6540,17 @@ if (typeof window !== 'undefined') {
// Update add button state
const addButton = itemsContainer.nextElementSibling;
- if (addButton) {
- const maxItems = parseInt(addButton.getAttribute('onclick').match(/\d+/)[0]);
- if (remainingItems.length < maxItems) {
- addButton.disabled = false;
- addButton.style.opacity = '1';
- addButton.style.cursor = 'pointer';
+ if (addButton && addButton.getAttribute('onclick')) {
+ // Extract maxItems from onclick attribute more safely
+ // Pattern: addArrayObjectItem('fieldId', 'fullKey', maxItems)
+ const onclickMatch = addButton.getAttribute('onclick').match(/addArrayObjectItem\s*\([^,]+,\s*[^,]+,\s*(\d+)\)/);
+ if (onclickMatch && onclickMatch[1]) {
+ const maxItems = parseInt(onclickMatch[1]);
+ if (remainingItems.length < maxItems) {
+ addButton.disabled = false;
+ addButton.style.opacity = '1';
+ addButton.style.cursor = 'pointer';
+ }
}
}
}