Skip to content

Commit a69286b

Browse files
authored
Introduce survey element getPanelInDesignMode function (#10572)
1 parent 8c66c00 commit a69286b

File tree

8 files changed

+34
-2
lines changed

8 files changed

+34
-2
lines changed

packages/survey-core/src/page.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export class PageModel extends PanelModel implements IPage {
7070
public getTemplate(): string {
7171
return this.isPanel ? "panel" : super.getTemplate();
7272
}
73+
public getPanelInDesignMode(): PanelModel { return null; }
7374
public get no(): string {
7475
if (!this.canShowPageNumber() || !this.survey) return "";
7576
let no = this.isStartPage ? "" : this.num + ". ";

packages/survey-core/src/panel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,6 +2215,7 @@ export class PanelModel extends PanelModelBase implements IElement {
22152215
public moveTo(container: IPanel, insertBefore: any = null): boolean {
22162216
return this.moveToBase(this.parent, container, insertBefore);
22172217
}
2218+
public getPanelInDesignMode(): PanelModel { return this; }
22182219
/**
22192220
* Returns the visible index of the panel in the survey. Commonly it is -1 and it doesn't show.
22202221
* You have to set showNumber to true to show index/numbering for the Panel

packages/survey-core/src/question_matrixdropdownbase.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,8 +1217,10 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel<Mat
12171217
return this.detailPanelValue;
12181218
}
12191219
public getPanels(): Array<IPanel> {
1220-
return [this.detailPanel];
1220+
const pnl = this.getPanelInDesignMode();
1221+
return !!pnl ? [pnl] : null;
12211222
}
1223+
public getPanelInDesignMode(): PanelModel { return this.detailPanelMode !== "none" ? this.detailPanel : null; }
12221224
/**
12231225
* An array of survey elements (questions and panels) to be displayed in detail sections.
12241226
*

packages/survey-core/src/question_paneldynamic.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ export class QuestionPanelDynamicModel extends Question
385385
public get template(): PanelModel {
386386
return this.templateValue;
387387
}
388+
public getPanelInDesignMode() : PanelModel { return this.template; }
388389
public getPanels(): Array<IPanel> {
389390
return [this.template];
390391
}

packages/survey-core/src/survey-element.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ export class SurveyElement<E = any> extends SurveyElementCore implements ISurvey
357357
this.onParentQuestionChanged();
358358
}
359359
protected onParentQuestionChanged(): void { }
360+
public getPanelInDesignMode(): PanelModel { return null; }
360361
public updateElementVisibility(): void {
361362
this.setPropertyValue("isVisible", this.isVisible);
362363
}

packages/survey-core/tests/paneltests.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3804,3 +3804,7 @@ QUnit.test("page questionStartIndex, Issue#10523", function (assert) {
38043804
assert.equal(q6.no, "B.2.1", "q6, #1");
38053805
assert.equal(q7.no, "B.2.2", "q7, #1");
38063806
});
3807+
QUnit.test("Panel/Page getPanelInDesignMode", function (assert) {
3808+
assert.notOk(new PageModel("p1").getPanelInDesignMode(), "page returns null");
3809+
assert.equal(new PanelModel("p1").getPanelInDesignMode().name, "p1", "panel returns itself");
3810+
});

packages/survey-core/tests/question_matrixdropdownbasetests.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@ QUnit.test(" 213 123sad d213 sadsd", function (assert) {
2525
});
2626
QUnit.test("allowAdaptiveActions", function (assert) {
2727
const matrix = new QuestionMatrixDropdownModelBase("q1");
28+
matrix.detailPanelMode = "underRow";
2829
assert.equal(matrix.allowAdaptiveActions, false, "matrix.allowAdaptiveActions");
2930
assert.equal(matrix.getPanels()[0]["allowAdaptiveActions"], true, "matrix.panel.allowAdaptiveActions");
3031

3132
matrix.allowAdaptiveActions = false;
3233
assert.equal(matrix.allowAdaptiveActions, false, "matrix.allowAdaptiveActions");
3334
assert.equal(matrix.getPanels()[0]["allowAdaptiveActions"], false, "matrix.panel.allowAdaptiveActions");
34-
35+
matrix.detailPanelMode = "none";
36+
matrix.allowAdaptiveActions = true;
37+
assert.equal(matrix.allowAdaptiveActions, true, "matrix.allowAdaptiveActions, #1");
38+
matrix.allowAdaptiveActions = false;
39+
assert.equal(matrix.allowAdaptiveActions, false, "matrix.allowAdaptiveActions, #2");
3540
});
3641

3742
QUnit.test("verticalLayout when isMobile set 'true'", function (assert) {
@@ -2382,3 +2387,15 @@ QUnit.test("Do not send data notification on creating detail panel, Bug#10253",
23822387
assert.equal(survey.state, "completed", "survey.state");
23832388
assert.equal(counter, 0, "#2");
23842389
});
2390+
QUnit.test("matrices getPanelInDesignMode", function (assert) {
2391+
const q1 = new QuestionMatrixDropdownModel("q1");
2392+
assert.notOk(q1.getPanelInDesignMode(), "#1");
2393+
q1.detailPanelMode = "underRow";
2394+
assert.ok(q1.getPanelInDesignMode(), "#2");
2395+
assert.strictEqual(q1.getPanelInDesignMode(), q1.detailPanel, "#3");
2396+
q1.detailPanelMode = "none";
2397+
assert.notOk(q1.getPanelInDesignMode(), "#4");
2398+
q1.detailPanelMode = "underRowSingle";
2399+
assert.ok(q1.getPanelInDesignMode(), "#5");
2400+
assert.strictEqual(q1.getPanelInDesignMode(), q1.detailPanel, "#6");
2401+
});

packages/survey-core/tests/question_paneldynamic_tests.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8991,3 +8991,8 @@ QUnit.test("Panel dynamic vs visibleIf & dots in question names, Bug#10505", fun
89918991
q088_5.value = false;
89928992
assert.equal(q090.isVisible, true, "q090 visible #5");
89938993
});
8994+
QUnit.test("paneldynamic getPanelInDesignMode", function (assert) {
8995+
assert.notOk(new QuestionTextModel("q1").getPanelInDesignMode(), "text returns null");
8996+
const q1 = new QuestionPanelDynamicModel("q1");
8997+
assert.strictEqual(q1.getPanelInDesignMode(), q1.template, "returns tempalte");
8998+
});

0 commit comments

Comments
 (0)