diff --git a/src/Wizard.js b/src/Wizard.js index 35c800f497..c748bf168b 100644 --- a/src/Wizard.js +++ b/src/Wizard.js @@ -60,14 +60,14 @@ export default class Wizard extends Webform { getPages(args = {}) { const { all = false } = args; - const pages = this.hasExtraPages ? this.components : this.pages; + const pages = this.hasSubWizards ? this.components : this.pages; const filteredPages = pages .filter(all ? _.identity : (p, index) => this._seenPages.includes(index)); return filteredPages; } - get hasExtraPages() { + get hasSubWizards() { return !_.isEmpty(this.subWizards); } @@ -217,7 +217,7 @@ export default class Wizard extends Webform { const ctx = this.renderContext; if (this.component.key) { - ctx.panels.map(panel => { + ctx.panels.forEach(panel => { if (panel.key === this.component.key) { this.currentPanel = panel; ctx.wizardPageTooltip = this.getFormattedTooltip(panel.tooltip); @@ -676,7 +676,7 @@ export default class Wizard extends Webform { this.getNextPage(); let parentNum = num; - if (this.hasExtraPages) { + if (this.hasSubWizards) { const pageFromPages = this.pages[num]; const pageFromComponents = this.components[num]; if (!pageFromComponents || pageFromPages?.id !== pageFromComponents.id) { @@ -1005,25 +1005,26 @@ export default class Wizard extends Webform { this.showErrors(errors, true, true); } - // If the pages change, need to redraw the header. let currentPanels; - let panels; + let newlyEstablishedPanels; const currentNextPage = this.currentNextPage; - if (this.hasExtraPages) { + if (this.hasSubWizards) { currentPanels = this.pages.map(page => page.component.key); this.establishPages(); - panels = this.pages.map(page => page.component.key); + newlyEstablishedPanels = this.pages.map(page => page.component.key); } else { currentPanels = this.currentPanels || this.pages.map(page => page.component.key); - panels = this.establishPages().map(panel => panel.key); - this.currentPanels = panels; + newlyEstablishedPanels = this.establishPages().map(panel => panel.key); + this.currentPanels = newlyEstablishedPanels; if (this.currentPanel?.key && this.currentPanels?.length) { this.setPage(this.currentPanels.findIndex(panel => panel === this.currentPanel.key)); } } - - if (!_.isEqual(panels, currentPanels) || (flags && flags.fromSubmission)) { + if (!_.isEqual(newlyEstablishedPanels, currentPanels) || (flags && flags.fromSubmission)) { + // if (this.hasSubWizards) { + this.setPage(this.pages.findIndex(page => page.component.id === this.currentPanel.id)); + // } this.redrawHeader(); } @@ -1074,7 +1075,7 @@ export default class Wizard extends Webform { } showErrors(errors, triggerEvent) { - if (this.hasExtraPages) { + if (this.hasSubWizards) { this.subWizards.forEach((subWizard) => { if(Array.isArray(subWizard.errors)) { errors = [...errors, ...subWizard.errors]