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) 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)]);