diff --git a/themes/grav/app/forms/fields/collections.js b/themes/grav/app/forms/fields/collections.js index c9c1ee90..81561045 100644 --- a/themes/grav/app/forms/fields/collections.js +++ b/themes/grav/app/forms/fields/collections.js @@ -231,11 +231,15 @@ export default class CollectionsField { // special case to preserve array field index keys if (prop === 'name' && element.data('gravArrayType')) { const match_index = element.attr(prop).match(/\[[0-9]{1,}\]$/); - const pattern = element[0].closest('[data-grav-array-name]').dataset.gravArrayName; - if (match_index && pattern) { + const array_container = element[0].closest('[data-grav-array-name]'); + + if (match_index) { array_index = match_index[0]; - element.attr(prop, `${pattern}${match_index[0]}`); - return; + element.attr(prop, element.attr(prop).slice(0, array_index.length * -1)); + } + + if (array_container && array_container.dataset && array_container.dataset.gravArrayName) { + element.attr(prop, array_container.dataset.gravArrayName); } } @@ -255,14 +259,8 @@ export default class CollectionsField { let matchedKey = currentKey; let replaced = element.attr(prop).replace(regexps[0], (/* str, p1, offset */) => { - let extras = ''; - if (array_index) { - extras = array_index; - console.log(indexes, extras); - } - matchedKey = indexes.shift() || matchedKey; - return `[${matchedKey}]${extras}`; + return `[${matchedKey}]`; }); replaced = replaced.replace(regexps[1], (/* str, p1, offset */) => { @@ -270,7 +268,7 @@ export default class CollectionsField { return `.${matchedKey}.`; }); - element.attr(prop, replaced); + element.attr(prop, array_index ? `${replaced}${array_index}` : replaced); }); }); }); diff --git a/themes/grav/js/admin.min.js b/themes/grav/js/admin.min.js index a1cff002..9ada14c2 100644 --- a/themes/grav/js/admin.min.js +++ b/themes/grav/js/admin.min.js @@ -5723,11 +5723,13 @@ var CollectionsField = /*#__PURE__*/function () { // special case to preserve array field index keys if (prop === 'name' && element.data('gravArrayType')) { var match_index = element.attr(prop).match(/\[[0-9]{1,}\]$/); - var pattern = element[0].closest('[data-grav-array-name]').dataset.gravArrayName; - if (match_index && pattern) { + var array_container = element[0].closest('[data-grav-array-name]'); + if (match_index) { array_index = match_index[0]; - element.attr(prop, "".concat(pattern).concat(match_index[0])); - return; + element.attr(prop, element.attr(prop).slice(0, array_index.length * -1)); + } + if (array_container && array_container.dataset && array_container.dataset.gravArrayName) { + element.attr(prop, array_container.dataset.gravArrayName); } } if (hasCustomKey && !observedValue) { @@ -5746,20 +5748,15 @@ var CollectionsField = /*#__PURE__*/function () { var matchedKey = currentKey; var replaced = element.attr(prop).replace(regexps[0], function /* str, p1, offset */ () { - var extras = ''; - if (array_index) { - extras = array_index; - console.log(indexes, extras); - } matchedKey = indexes.shift() || matchedKey; - return "[".concat(matchedKey, "]").concat(extras); + return "[".concat(matchedKey, "]"); }); replaced = replaced.replace(regexps[1], function /* str, p1, offset */ () { matchedKey = indexes.shift() || matchedKey; return ".".concat(matchedKey, "."); }); - element.attr(prop, replaced); + element.attr(prop, array_index ? "".concat(replaced).concat(array_index) : replaced); }); }); });