Skip to content

Commit

Permalink
dispose question/panel/page on calling delete() fix #6676 (#6677)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov authored Aug 8, 2023
1 parent 8cdbc30 commit 9c7c933
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ export class PageModel extends PanelModelBase implements IPage {
public set passed(val: boolean) {
this.setPropertyValue("passed", val);
}
public delete() {
protected removeFromParent(): void {
if (!!this.survey) {
this.removeSelfFromList(this.survey.pages);
}
}
public onFirstRendering() {
public onFirstRendering(): void {
if (this.wasShown) return;
super.onFirstRendering();
}
Expand Down
7 changes: 6 additions & 1 deletion src/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ export class PanelModelBase extends SurveyElement<Question>
(this.showTitle && this.isDesignMode && settings.designMode.showEmptyTitles)
);
}
public delete(): void {
this.removeFromParent();
this.dispose();
}
protected removeFromParent(): void {}
protected canShowTitle(): boolean { return true; }
@property({ defaultValue: true }) showDescription: boolean;
get _showDescription(): boolean {
Expand Down Expand Up @@ -1548,7 +1553,7 @@ export class PanelModel extends PanelModelBase implements IElement {
public set page(val: IPage) {
this.setPage(this.parent, val);
}
public delete() {
protected removeFromParent(): void {
if (!!this.parent) {
this.removeSelfFromList(this.parent.elements);
}
Expand Down
6 changes: 5 additions & 1 deletion src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ export class Question extends SurveyElement<Question>
return null;
}
public delete(): void {
this.removeFromParent();
this.dispose();
}
protected removeFromParent(): void {
if (!!this.parent) {
this.removeSelfFromList(this.parent.elements);
}
Expand Down Expand Up @@ -450,7 +454,7 @@ export class Question extends SurveyElement<Question>
}
public set parent(val: IPanel) {
if (this.parent === val) return;
this.delete();
this.removeFromParent();
this.setPropertyValue("parent", val);
this.updateQuestionCss();
this.onParentChanged();
Expand Down
15 changes: 15 additions & 0 deletions tests/question_baseselecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,21 @@ QUnit.test("Carry Forward and keepIncorrectValues, bug#6490", function (assert)
survey.doComplete();
assert.deepEqual(survey.data, { q1: "B", q2: "X" }, "keep value on compete");
});
QUnit.test("Check isUsingCarryForward on deleting question", function (assert) {
const survey = new SurveyModel();
survey.setDesignMode(true);
survey.fromJSON({ elements: [
{ type: "dropdown", name: "q1", choices: ["B", "A", "D", "C"] },
{ type: "dropdown", name: "q2", choicesFromQuestion: "q1" }
] });
const q1 = <QuestionSelectBase>survey.getQuestionByName("q1");
const q2 = <QuestionSelectBase>survey.getQuestionByName("q2");
assert.equal(q2.choicesFromQuestion, "q1", "set correctly");
assert.equal(q2.isUsingCarryForward, true, "Carryforward flag is set");
q1.delete();
assert.notOk(q2.choicesFromQuestion, "it is empty");
assert.equal(q2.isUsingCarryForward, false, "Carryforward flag is unset");
});
QUnit.test("Do not notify survey on changing newItem.value", function (
assert
) {
Expand Down

0 comments on commit 9c7c933

Please sign in to comment.