From 0c39df2b085705abbafbafa987406a5aefec6a34 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Fri, 10 Jan 2025 12:08:31 +0000 Subject: [PATCH 1/2] Update error indexes when replicator set is removed --- .../fieldtypes/replicator/Replicator.vue | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/resources/js/components/fieldtypes/replicator/Replicator.vue b/resources/js/components/fieldtypes/replicator/Replicator.vue index 5744aadf50..cf61498600 100644 --- a/resources/js/components/fieldtypes/replicator/Replicator.vue +++ b/resources/js/components/fieldtypes/replicator/Replicator.vue @@ -194,6 +194,30 @@ export default { }, removed(set, index) { + let errors = this.storeState.errors || {}; + + errors = Object.keys(errors).reduce((acc, key) => { + if (key.startsWith(`${this.fieldPathPrefix || this.handle}.${index}.`)) { + return acc; + } + + if (key.startsWith(`${this.fieldPathPrefix || this.handle}.`)) { + const parts = key.split('.'); + const setIndex = parseInt(parts[1], 10); + + if (setIndex > index) { + parts[1] = (setIndex - 1).toString(); + acc[parts.join('.')] = errors[key]; + } else { + acc[key] = errors[key]; + } + } + + return acc; + }, {}); + + this.$store.commit(`publish/${this.storeName}/setErrors`, errors); + this.removeSetMeta(set._id); this.update([...this.value.slice(0, index), ...this.value.slice(index + 1)]); From a801e5fb5e5cab1bc80cd12cbe5bcd5b18548ad3 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Fri, 10 Jan 2025 12:11:43 +0000 Subject: [PATCH 2/2] Update error indexes when grid row is removed --- .../js/components/fieldtypes/grid/Grid.vue | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/resources/js/components/fieldtypes/grid/Grid.vue b/resources/js/components/fieldtypes/grid/Grid.vue index abab666916..2f14c33442 100644 --- a/resources/js/components/fieldtypes/grid/Grid.vue +++ b/resources/js/components/fieldtypes/grid/Grid.vue @@ -155,6 +155,10 @@ export default { ]; }, + storeState() { + return this.$store.state.publish[this.storeName] || {}; + }, + }, watch: { @@ -207,6 +211,30 @@ export default { removed(index) { if (! confirm(__('Are you sure?'))) return; + let errors = this.storeState.errors || {}; + + errors = Object.keys(errors).reduce((acc, key) => { + if (key.startsWith(`${this.fieldPathPrefix || this.handle}.${index}.`)) { + return acc; + } + + if (key.startsWith(`${this.fieldPathPrefix || this.handle}.`)) { + const parts = key.split('.'); + const rowIndex = parseInt(parts[1], 10); + + if (rowIndex > index) { + parts[1] = (rowIndex - 1).toString(); + acc[parts.join('.')] = errors[key]; + } else { + acc[key] = errors[key]; + } + } + + return acc; + }, {}); + + this.$store.commit(`publish/${this.storeName}/setErrors`, errors); + this.update([ ...this.value.slice(0, index), ...this.value.slice(index + 1)