Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

survey keeps delete questions if they were in a deleted panel fix #8458 #8459

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,22 @@ export class PanelModelBase extends SurveyElement<Question>
);
}
public delete(doDispose: boolean = true): void {
this.deletePanel();
this.removeFromParent();
if(doDispose) {
this.dispose();
}
}
private deletePanel(): void {
const els = this.elements;
for(let i = 0; i < els.length; i ++) {
const el = els[i];
if(el.isPanel) {
(<PanelModelBase><any>el).deletePanel();
}
this.onRemoveElementNotifySurvey(el);
}
}
protected removeFromParent(): void {}
protected canShowTitle(): boolean { return true; }
@property({ defaultValue: true }) showDescription: boolean;
Expand Down Expand Up @@ -1296,13 +1307,17 @@ export class PanelModelBase extends SurveyElement<Question>
(<Base>(<any>element)).unregisterPropertyChangedHandlers(["visible", "isVisible", "startWithNewLine"], this.id);
this.updateRowsOnElementRemoved(element);
if (this.isRandomizing) return;
this.onRemoveElementNotifySurvey(element);
if (!!this.removeElementCallback) this.removeElementCallback(element);
this.onElementVisibilityChanged(this);
}
private onRemoveElementNotifySurvey(element: IElement): void {
if(!this.survey) return;
if (!element.isPanel) {
if (this.survey) this.survey.questionRemoved(<Question>element);
this.survey.questionRemoved(<Question>element);
} else {
if (this.survey) this.survey.panelRemoved(element);
this.survey.panelRemoved(element);
}
if (!!this.removeElementCallback) this.removeElementCallback(element);
this.onElementVisibilityChanged(this);
}
private onElementVisibilityChanged(element: any) {
if (this.isLoadingFromJson || this.isRandomizing) return;
Expand Down
30 changes: 29 additions & 1 deletion tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19948,4 +19948,32 @@ QUnit.test("Display mode in design time 2", function (assert) {

survey.backgroundImageAttachment = "fixed";
assert.equal(survey.wrapperFormCss, "sd-root-modern__wrapper sd-root-modern__wrapper--has-image sd-root-modern__wrapper--fixed");
});
});
QUnit.test("Delete panel with questions", (assert) => {
const survey = new SurveyModel({
"elements": [
{
"type": "panel",
"name": "panel1",
"elements": [
{
"type": "text",
"name": "question1"
},
{
"type": "text",
"name": "question2"
}
]
},
]
});
assert.ok(survey.getPanelByName("panel1"), "#1");
assert.ok(survey.getQuestionByName("question1"), "#2");
assert.ok(survey.getQuestionByName("question2"), "#3");
survey.getQuestionByName("question2").delete();
assert.notOk(survey.getQuestionByName("question2"), "#4");
survey.getPanelByName("panel1").delete();
assert.notOk(survey.getPanelByName("panel1"), "#5");
assert.notOk(survey.getQuestionByName("question1"), "#6");
});
Loading