Skip to content

Commit

Permalink
A preview takes more time to open after the upgrade fix #8088 (#8090)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Apr 10, 2024
1 parent 5abc271 commit 3029e95
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/base-interfaces.ts
Expand Up @@ -56,7 +56,7 @@ export interface ISurvey extends ITextProcessor, ISurveyErrorOwner {
getQuestionByName(name: string): IQuestion;
pageVisibilityChanged(page: IPage, newValue: boolean): any;
panelVisibilityChanged(panel: IPanel, newValue: boolean): any;
questionVisibilityChanged(question: IQuestion, newValue: boolean): any;
questionVisibilityChanged(question: IQuestion, newValue: boolean, resetIndexes: boolean): any;
isEditingSurveyElement: boolean;
getQuestionClearIfInvisible(questionClearIf: string): string;
questionsOrder: string;
Expand Down
6 changes: 4 additions & 2 deletions src/question.ts
Expand Up @@ -665,9 +665,11 @@ export class Question extends SurveyElement<Question>
}
public getTitleOwner(): ITitleOwner { return this; }
protected getIsTitleRenderedAsString(): boolean { return this.titleLocation === "hidden"; }
private notifySurveyVisibilityChanged() {
protected notifySurveyOnChildrenVisibilityChanged(): boolean { return false; }
private notifySurveyVisibilityChanged(): void {
if (!this.survey || this.isLoadingFromJson) return;
this.survey.questionVisibilityChanged(this, this.isVisible);
this.survey.questionVisibilityChanged(this, this.isVisible,
!this.parentQuestion || this.parentQuestion.notifySurveyOnChildrenVisibilityChanged());
const isClearOnHidden = this.isClearValueOnHidden;
if (!this.visible) {
this.clearValueOnHidding(isClearOnHidden);
Expand Down
12 changes: 7 additions & 5 deletions src/question_paneldynamic.ts
Expand Up @@ -1000,9 +1000,10 @@ export class QuestionPanelDynamicModel extends Question
public set showQuestionNumbers(val: string) {
this.setPropertyValue("showQuestionNumbers", val);
if (!this.isLoadingFromJson && this.survey) {
this.survey.questionVisibilityChanged(this, this.visible);
this.survey.questionVisibilityChanged(this, this.visible, true);
}
}
protected notifySurveyOnChildrenVisibilityChanged(): boolean { return this.showQuestionNumbers === "onSurvey"; }
/**
* Specifies the location of the Delete Panel button relative to panel content.
*
Expand Down Expand Up @@ -1071,19 +1072,20 @@ export class QuestionPanelDynamicModel extends Question
}
public setVisibleIndex(value: number): number {
if (!this.isVisible) return 0;
var startIndex = this.showQuestionNumbers == "onSurvey" ? value : 0;
const onSurveyNumbering = this.showQuestionNumbers === "onSurvey";
var startIndex = onSurveyNumbering ? value : 0;
for (var i = 0; i < this.visiblePanelsCore.length; i++) {
var counter = this.setPanelVisibleIndex(
this.visiblePanelsCore[i],
startIndex,
this.showQuestionNumbers != "off"
);
if (this.showQuestionNumbers == "onSurvey") {
if (onSurveyNumbering) {
startIndex += counter;
}
}
super.setVisibleIndex(this.showQuestionNumbers != "onSurvey" ? value : -1);
return this.showQuestionNumbers != "onSurvey" ? 1 : startIndex - value;
super.setVisibleIndex(!onSurveyNumbering ? value : -1);
return !onSurveyNumbering ? 1 : startIndex - value;
}
private setPanelVisibleIndex(
panel: PanelModel,
Expand Down
12 changes: 7 additions & 5 deletions src/survey.ts
Expand Up @@ -4685,8 +4685,8 @@ export class SurveyModel extends SurveyElementCore
return res;
}
private isCalculatingProgressText = false;
public updateProgressText(onValueChanged: boolean = false) {
if (this.isCalculatingProgressText) return;
public updateProgressText(onValueChanged: boolean = false): void {
if (this.isCalculatingProgressText || this.isShowingPreview || this.isLockingUpdateOnPageModes) return;
if (
onValueChanged &&
this.progressBarType == "pages" &&
Expand Down Expand Up @@ -6057,7 +6057,7 @@ export class SurveyModel extends SurveyElementCore
this.updateVisibleIndexes();
}
private updateVisibleIndexes() {
if (this.isLoadingFromJson || !!this.isEndLoadingFromJson) return;
if (this.isLoadingFromJson || !!this.isEndLoadingFromJson || this.isLockingUpdateOnPageModes) return;
if (
this.isRunningConditions &&
this.onQuestionVisibleChanged.isEmpty &&
Expand Down Expand Up @@ -6655,8 +6655,10 @@ export class SurveyModel extends SurveyElementCore
if (questionClearIf !== "default") return questionClearIf;
return this.clearInvisibleValues;
}
questionVisibilityChanged(question: Question, newValue: boolean) {
this.updateVisibleIndexes();
questionVisibilityChanged(question: Question, newValue: boolean, resetIndexes: boolean): void {
if(resetIndexes) {
this.updateVisibleIndexes();
}
this.onQuestionVisibleChanged.fire(this, {
question: question,
name: question.name,
Expand Down
17 changes: 17 additions & 0 deletions tests/question_paneldynamic_tests.ts
Expand Up @@ -6838,3 +6838,20 @@ QUnit.test("panel dynamic & panel visibleIf & checkbox vs carry forward, #7693",
]
});
});
QUnit.test("onQuestionVisibleChanged should be fired", function (assert) {
const survey = new SurveyModel({
elements: [
{ type: "text", name: "q1" },
{ type: "paneldynamic", name: "q2", panelCount: 1,
templateElements: [{ type: "text", name: "q3", visibleIf: "{q1} = 1" }, { type: "text", name: "q4" }]
}
]
});
const questionNames = new Array<string>();
survey.onQuestionVisibleChanged.add((sender, options) => {
questionNames.push(options.question.name + ":" + options.question.isVisible);
});
survey.setValue("q1", 1);
survey.setValue("q1", 2);
assert.deepEqual(questionNames, ["q3:true", "q3:false"], "visiblity logs");
});
34 changes: 34 additions & 0 deletions tests/surveytests.ts
Expand Up @@ -19501,3 +19501,37 @@ QUnit.test("page passed", function (assert) {
assert.ok(survey.pages[0].passed, "First page passed");
assert.ok(survey.pages[1].passed, "Second page passed");
});
QUnit.test("showPreview & updateProgress & updateVisibleIndexes", function (
assert
) {
const survey = new SurveyModel({
showProgressBar: "top",
progressBarType: "buttons",
progressBarShowPageTitles: true,
pages: [
{
elements: [{ type: "text", name: "q1" }]
},
{
elements: [
{ type: "paneldynamic", name: "q2", panelCount: 10,
elements: [{ type: "text", name: "q3", visibleIf: "{q1} = 1" }]
},
{ type: "text", name: "q4", visibleIf: "{q1} = 1" }
]
}
]
});
survey.data = { q1: 1 };
let progressCounter = 0;
let visibleChangedCounter = 0;
survey.onProgressText.add((sender, options) => {
progressCounter ++;
});
survey.onQuestionVisibleChanged.add((sender, options) => {
visibleChangedCounter ++;
});
survey.showPreview();
assert.equal(progressCounter, 1, "progressCounter");
assert.equal(visibleChangedCounter, 0, "visibleChangedCounter");
});

0 comments on commit 3029e95

Please sign in to comment.