From 4ab7c77257581dd485d0a0b4440eb697bbf5637a Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 12 Oct 2022 10:57:40 +0200 Subject: [PATCH] FIX: fix wizard index creation --- .../discourse/components/wizard-links.js.es6 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/components/wizard-links.js.es6 b/assets/javascripts/discourse/components/wizard-links.js.es6 index bf0dd242..de5f8dd3 100644 --- a/assets/javascripts/discourse/components/wizard-links.js.es6 +++ b/assets/javascripts/discourse/components/wizard-links.js.es6 @@ -71,6 +71,16 @@ export default Component.extend({ }); }, + getNextIndex() { + const items = this.items; + if (!items || items.length === 0) { + return 0; + } + const lastItem = items[items.length - 1]; + const lastNumber = lastItem.id.split("_").pop(); + return Number(lastNumber); + }, + actions: { add() { const items = this.get("items"); @@ -78,7 +88,7 @@ export default Component.extend({ let params = setWizardDefaults({}, itemType); params.isNew = true; - params.index = items.length; + params.index = this.getNextIndex(); let id = `${itemType}_${params.index + 1}`; if (itemType === "field") {