looks like a fix for deeply nested sortable fields!

Signed-off-by: Andy Miller <rhuk@mac.com>
This commit is contained in:
Andy Miller
2025-09-19 21:15:28 -06:00
parent 6d673fc7c4
commit a8ac6f8573
2 changed files with 18 additions and 23 deletions

View File

@@ -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);
});
});
});