Skip to content

Commit

Permalink
Add doDispose parameter into surveyelement delete function
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Aug 29, 2023
1 parent 0d3d049 commit b544af8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/base-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export interface ISurveyElement extends IShortcutText {
getType(): string;
setVisibleIndex(value: number): number;
locStrsChanged(): any;
delete(): any;
delete(doDispose?: boolean): void;
toggleState(): void;
stateChangedCallback(): void;
getTitleToolbar(): AdaptiveActionContainer;
Expand Down
6 changes: 4 additions & 2 deletions src/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,11 @@ export class PanelModelBase extends SurveyElement<Question>
(this.showTitle && this.isDesignMode && settings.designMode.showEmptyTitles)
);
}
public delete(): void {
public delete(doDispose: boolean = true): void {
this.removeFromParent();
this.dispose();
if(doDispose) {
this.dispose();
}
}
protected removeFromParent(): void {}
protected canShowTitle(): boolean { return true; }
Expand Down
13 changes: 10 additions & 3 deletions src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,13 @@ export class Question extends SurveyElement<Question>
public getPanel(): IPanel {
return null;
}
public delete(): void {
public delete(doDispose: boolean = true): void {
this.removeFromParent();
this.dispose();
if(doDispose) {
this.dispose();
} else {
this.resetDependedQuestions();
}
}
protected removeFromParent(): void {
if (!!this.parent) {
Expand Down Expand Up @@ -2324,10 +2328,13 @@ export class Question extends SurveyElement<Question>
}
public dispose(): void {
super.dispose();
this.resetDependedQuestions();
this.destroyResizeObserver();
}
private resetDependedQuestions(): void {
for (var i = 0; i < this.dependedQuestions.length; i++) {
this.dependedQuestions[i].resetDependedQuestion();
}
this.destroyResizeObserver();
}
}
function makeNameValid(str: string): string {
Expand Down
2 changes: 1 addition & 1 deletion src/survey-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ export class SurveyElement<E = any> extends SurveyElementCore implements ISurvey
public get isQuestion() {
return false;
}
public delete() { }
public delete(doDispose: boolean): void { }
//ILocalizableOwner
locOwner: ILocalizableOwner;
/**
Expand Down
15 changes: 15 additions & 0 deletions tests/question_baseselecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,21 @@ QUnit.test("Check isUsingCarryForward on deleting matrix dynamic question", func
assert.notOk(q2.choicesFromQuestion, "it is empty");
assert.equal(q2.isUsingCarryForward, false, "Carryforward flag is unset");
});
QUnit.test("Check isUsingCarryForward on deleting matrix dynamic question with doDispose = false parameter", function (assert) {
const survey = new SurveyModel();
survey.setDesignMode(true);
survey.fromJSON({ elements: [
{ type: "matrixdynamic", name: "q1" },
{ 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(false);
assert.notOk(q2.choicesFromQuestion, "it is empty");
assert.equal(q2.isUsingCarryForward, false, "Carryforward flag is unset");
});
QUnit.test("Use carryForward with panel dynamic + update data on survey.data=data;", function (assert) {
const survey = new SurveyModel({ elements: [
{ type: "checkbox", name: "q2", choicesFromQuestion: "q1", choiceValuesFromQuestion: "q1-q2", choiceTextsFromQuestion: "q1-q3" },
Expand Down

0 comments on commit b544af8

Please sign in to comment.