From 92507db9746382c9d9cdb7465db6065fe70aa03f Mon Sep 17 00:00:00 2001 From: Stuart Romanek Date: Wed, 15 Jan 2025 13:30:57 -0500 Subject: [PATCH] convert arrays isModified to computed, revert double check --- CHANGELOG.md | 1 + .../schema/ui/apos/logic/AposArrayEditor.js | 41 ++++++++++--------- .../ui/ui/apos/mixins/AposModifiedMixin.js | 3 +- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8386ea3914..a247796fa8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ ### Changes * The `pickerOptions` sub property of a color field's configuration has been merged with it's parent `options` object. +* The array editor's `isModified` method is now a computed property for consistency. ## 4.11.2 (2024-12-29) diff --git a/modules/@apostrophecms/schema/ui/apos/logic/AposArrayEditor.js b/modules/@apostrophecms/schema/ui/apos/logic/AposArrayEditor.js index ea37facee4..93dcc273c5 100644 --- a/modules/@apostrophecms/schema/ui/apos/logic/AposArrayEditor.js +++ b/modules/@apostrophecms/schema/ui/apos/logic/AposArrayEditor.js @@ -138,6 +138,26 @@ export default { }, currentDocMeta() { return this.meta[this.currentId]?.aposMeta || {}; + }, + isModified() { + if (this.currentId) { + const currentIndex = this.next.findIndex(item => item._id === this.currentId); + if (detectDocChange(this.schema, this.next[currentIndex], this.currentDoc.data)) { + return true; + } + } + if (this.next.length !== this.original.length) { + return true; + } + for (let i = 0; (i < this.next.length); i++) { + if (this.next[i]._id !== this.original[i]._id) { + return true; + } + if (detectDocChange(this.schema, this.next[i], this.original[i])) { + return true; + } + } + return false; } }, async mounted() { @@ -242,26 +262,7 @@ export default { getFieldValue(name) { return this.currentDoc.data[name]; }, - isModified() { - if (this.currentId) { - const currentIndex = this.next.findIndex(item => item._id === this.currentId); - if (detectDocChange(this.schema, this.next[currentIndex], this.currentDoc.data)) { - return true; - } - } - if (this.next.length !== this.original.length) { - return true; - } - for (let i = 0; (i < this.next.length); i++) { - if (this.next[i]._id !== this.original[i]._id) { - return true; - } - if (detectDocChange(this.schema, this.next[i], this.original[i])) { - return true; - } - } - return false; - }, + async validate(validateItem, validateLength) { if (validateItem && this.next.length > 0 && this.currentId) { this.triggerValidation = true; diff --git a/modules/@apostrophecms/ui/ui/apos/mixins/AposModifiedMixin.js b/modules/@apostrophecms/ui/ui/apos/mixins/AposModifiedMixin.js index b3df8e078b..cdfdfb3160 100644 --- a/modules/@apostrophecms/ui/ui/apos/mixins/AposModifiedMixin.js +++ b/modules/@apostrophecms/ui/ui/apos/mixins/AposModifiedMixin.js @@ -25,8 +25,7 @@ export default { // Returns true if the cancellation does occur async confirmAndCancel() { let dismiss; - const modified = typeof this.isModified === 'function' ? this.isModified() : this.isModified; - if (modified) { + if (this.isModified) { const discard = await apos.confirm({ heading: this.cancelHeading, description: this.cancelDescription,