Fixed issue with array field nested in list that were losing their index order when the list reordered

This commit is contained in:
Djamil Legato
2019-07-17 10:42:01 -07:00
parent d85a6777de
commit 1542931d99
3 changed files with 15 additions and 2 deletions

View File

@@ -8,6 +8,7 @@
* Fixed 2FA regenerate for Flex Users * Fixed 2FA regenerate for Flex Users
* Added missing closing </li> in language loops * Added missing closing </li> in language loops
* Fixed issue with nested `list` fields both utilizing the custom `key` functionality * Fixed issue with nested `list` fields both utilizing the custom `key` functionality
* Fixed issue with `array` field nested in `list` that were losing their index order when the list reordered
# v1.9.7 # v1.9.7
## 06/21/2019 ## 06/21/2019

View File

@@ -177,11 +177,20 @@ export default class CollectionsField {
item.find('[' + prop + '], [_' + prop + ']').each(function() { item.find('[' + prop + '], [_' + prop + ']').each(function() {
let element = $(this); let element = $(this);
let indexes = []; let indexes = [];
let array_index = null;
let regexps = [ let regexps = [
new RegExp('\\[(\\d+|\\*|' + currentKey + ')\\]', 'g'), new RegExp('\\[(\\d+|\\*|' + currentKey + ')\\]', 'g'),
new RegExp('\\.(\\d+|\\*|' + currentKey + ')\\.', 'g') new RegExp('\\.(\\d+|\\*|' + currentKey + ')\\.', 'g')
]; ];
// special case to preserve array field index keys
if (prop === 'name' && element.data('gravArrayType')) {
const match_index = element.attr(prop).match(/\[\d+\]$/);
if (match_index) {
array_index = match_index[0];
}
}
if (hasCustomKey && !observedValue) { if (hasCustomKey && !observedValue) {
element.attr(`_${prop}`, element.attr(prop)); element.attr(`_${prop}`, element.attr(prop));
element.attr(prop, null); element.attr(prop, null);
@@ -198,8 +207,11 @@ export default class CollectionsField {
let matchedKey = currentKey; let matchedKey = currentKey;
let replaced = element.attr(prop).replace(regexps[0], (/* str, p1, offset */) => { let replaced = element.attr(prop).replace(regexps[0], (/* str, p1, offset */) => {
let extras = '';
if (array_index) { extras = array_index; }
matchedKey = indexes.shift() || matchedKey; matchedKey = indexes.shift() || matchedKey;
return `[${matchedKey}]`; return `[${matchedKey}]${extras}`;
}); });
replaced = replaced.replace(regexps[1], (/* str, p1, offset */) => { replaced = replaced.replace(regexps[1], (/* str, p1, offset */) => {

File diff suppressed because one or more lines are too long