Skip to content

Commit 7b4cacb

Browse files
authored
Merge pull request #5913 from formio/fio-9241
FIO-9241: Correctly set current page after conditionally hiding page in sibling nested wizard
2 parents 22800c1 + 5ccc183 commit 7b4cacb

File tree

4 files changed

+508
-24
lines changed

4 files changed

+508
-24
lines changed

src/Wizard.js

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export default class Wizard extends Webform {
3737
this.originalComponents = [];
3838
this.page = 0;
3939
this.currentPanel = null;
40-
this.currentPanels = null;
4140
this.currentNextPage = 0;
4241
this._seenPages = [0];
4342
this.subWizards = [];
@@ -60,14 +59,14 @@ export default class Wizard extends Webform {
6059

6160
getPages(args = {}) {
6261
const { all = false } = args;
63-
const pages = this.hasExtraPages ? this.components : this.pages;
62+
const pages = this.hasSubWizards ? this.components : this.pages;
6463
const filteredPages = pages
6564
.filter(all ? _.identity : (p, index) => this._seenPages.includes(index));
6665

6766
return filteredPages;
6867
}
6968

70-
get hasExtraPages() {
69+
get hasSubWizards() {
7170
return !_.isEmpty(this.subWizards);
7271
}
7372

@@ -216,9 +215,9 @@ export default class Wizard extends Webform {
216215
render() {
217216
const ctx = this.renderContext;
218217

219-
if (this.component.key) {
220-
ctx.panels.map(panel => {
221-
if (panel.key === this.component.key) {
218+
if (this.component.id) {
219+
ctx.panels.forEach(panel => {
220+
if (panel.id === this.component.id) {
222221
this.currentPanel = panel;
223222
ctx.wizardPageTooltip = this.getFormattedTooltip(panel.tooltip);
224223
}
@@ -676,7 +675,7 @@ export default class Wizard extends Webform {
676675
this.getNextPage();
677676

678677
let parentNum = num;
679-
if (this.hasExtraPages) {
678+
if (this.hasSubWizards) {
680679
const pageFromPages = this.pages[num];
681680
const pageFromComponents = this.components[num];
682681
if (!pageFromComponents || pageFromPages?.id !== pageFromComponents.id) {
@@ -1018,24 +1017,18 @@ export default class Wizard extends Webform {
10181017
}
10191018

10201019
// If the pages change, need to redraw the header.
1021-
let currentPanels;
1022-
let panels;
1020+
const currentPanels = this.pages;
1021+
// calling this.establishPages() updates/mutates this.pages to be the current pages
1022+
this.establishPages();
1023+
const newPanels = this.pages;
10231024
const currentNextPage = this.currentNextPage;
1024-
if (this.hasExtraPages) {
1025-
currentPanels = this.pages.map(page => page.component.key);
1026-
this.establishPages();
1027-
panels = this.pages.map(page => page.component.key);
1025+
const panelsUpdated = !_.isEqual(newPanels, currentPanels);
1026+
1027+
if (this.currentPanel?.id && this.pages.length && (!this.hasSubWizards || (this.hasSubWizards && panelsUpdated))) {
1028+
const newIndex = this.pages.findIndex(page => page.id === this.currentPanel.id);
1029+
if (newIndex !== -1) this.setPage(newIndex);
10281030
}
1029-
else {
1030-
currentPanels = this.currentPanels || this.pages.map(page => page.component.key);
1031-
panels = this.establishPages().map(panel => panel.key);
1032-
this.currentPanels = panels;
1033-
if (this.currentPanel?.key && this.currentPanels?.length) {
1034-
this.setPage(this.currentPanels.findIndex(panel => panel === this.currentPanel.key));
1035-
}
1036-
}
1037-
1038-
if (!_.isEqual(panels, currentPanels) || (flags && flags.fromSubmission)) {
1031+
if (panelsUpdated || (flags && flags.fromSubmission)) {
10391032
this.redrawHeader();
10401033
}
10411034

src/components/_classes/nested/NestedComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ export default class NestedComponent extends Field {
737737

738738
validationProcessor({ scope, data, row, instance, paths }, flags) {
739739
const { dirty } = flags;
740-
if (this.root.hasExtraPages && this.page !== this.root.page) {
740+
if (this.root.hasSubWizards && this.page !== this.root.page) {
741741
instance = this.componentsMap?.hasOwnProperty(paths.dataPath)
742742
? this.componentsMap[paths.dataPath]
743743
: this.getComponent(paths.dataPath);

0 commit comments

Comments
 (0)