From f7e45a20ce3a7d7af3f00dedf912ed382850886d Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 28 Sep 2021 13:58:34 +0300 Subject: [PATCH] Fix: Navigation issue with onProgressText callback and questionOrder - random #3383 (#3388) --- src/panel.ts | 3 ++- tests/surveytests.ts | 60 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/panel.ts b/src/panel.ts index 60e20bc7fb..ebc750c403 100644 --- a/src/panel.ts +++ b/src/panel.ts @@ -985,6 +985,7 @@ export class PanelModelBase extends SurveyElement this.id ); this.updateRowsOnElementRemoved(element); + if(this.isRandomizing) return; if (!element.isPanel) { if (this.survey) this.survey.questionRemoved(element); } else { @@ -994,7 +995,7 @@ export class PanelModelBase extends SurveyElement this.onElementVisibilityChanged(this); } private onElementVisibilityChanged(element: any) { - if (this.isLoadingFromJson) return; + if (this.isLoadingFromJson || this.isRandomizing) return; this.updateRowsVisibility(element); this.childVisibilityChanged(); if (!!this.parent) { diff --git a/tests/surveytests.ts b/tests/surveytests.ts index 0114f02918..b4fac3739e 100644 --- a/tests/surveytests.ts +++ b/tests/surveytests.ts @@ -578,6 +578,66 @@ QUnit.test( assert.equal(survey.progressText, "Answered: 50%"); } ); +QUnit.test("onProgressText event and questionOrder in page, Bug#3383", function (assert) { + var survey = new SurveyModel({ + "pages": [ + { + name: "page1", + "elements": [ + { + "name": "q1", + "type": "radiogroup", + "choices": [1, 2, 3], + }, + ], + }, + { + name: "page2", + "elements": [ + { + "name": "q2", + "type": "text", + }, + { + "name": "q3", + "type": "radiogroup", + choices: [1, 2, 3], + } + ] + }, + { + name: "page3", + "elements": [ + { + "name": "q4", + "choices": [1, 2, 3], + "type": "radiogroup" + }, + { + "name": "q5", + "type": "text", + } + ], + "questionsOrder": "random" + } + ], + }); + var oldCurrentPageName: string; + var newCurrentPageName: string; + survey.onCurrentPageChanged.add((sender, options) => { + oldCurrentPageName = !!options.oldCurrentPage? options.oldCurrentPage.name : ""; + newCurrentPageName = !!options.newCurrentPage? options.newCurrentPage.name : ""; + }); + survey.onProgressText.add(() => { var dummy = 1; }); + survey.nextPage(); + assert.equal(oldCurrentPageName, "page1", "First nextPage, old"); + assert.equal(newCurrentPageName, "page2", "First nextPage, new"); + survey.nextPage(); + assert.equal(survey.currentPageNo, 2, "We are on the last page"); + assert.equal(oldCurrentPageName, "page2", "Second nextPage, old"); + assert.equal(newCurrentPageName, "page3", "Second nextPage, new"); +}); + QUnit.test("progressText, 'requiredQuestions' type and design mode", function ( assert ) {