Skip to content

Commit

Permalink
Dynamic Panel - The maxPanelCount property doesn't update panel footer
Browse files Browse the repository at this point in the history
…fix #8865 (#8867)
  • Loading branch information
andrewtelnov authored Sep 28, 2024
1 parent 652fea4 commit d5a22e1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/survey-core/src/question_paneldynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ export class QuestionPanelDynamicModel extends Question
this.updateFooterActions();
});
this.registerPropertyChangedHandlers(["allowAddPanel"], () => { this.updateNoEntriesTextDefaultLoc(); });
this.registerPropertyChangedHandlers(["minPanelCount"], () => { this.onMinPanelCountChanged(); });
this.registerPropertyChangedHandlers(["maxPanelCount"], () => { this.onMaxPanelCountChanged(); });
}
public get isCompositeQuestion(): boolean { return true; }
public get hasSingleInput(): boolean { return false; }
Expand Down Expand Up @@ -1043,8 +1045,10 @@ export class QuestionPanelDynamicModel extends Question
}
public set minPanelCount(val: number) {
if (val < 0) val = 0;
if (val == this.minPanelCount) return;
this.setPropertyValue("minPanelCount", val);
}
private onMinPanelCountChanged(): void {
const val = this.minPanelCount;
if (val > this.maxPanelCount) this.maxPanelCount = val;
if (this.panelCount < val) this.panelCount = val;
}
Expand All @@ -1063,10 +1067,14 @@ export class QuestionPanelDynamicModel extends Question
if (val <= 0) return;
if (val > settings.panel.maxPanelCount)
val = settings.panel.maxPanelCount;
if (val == this.maxPanelCount) return;
this.setPropertyValue("maxPanelCount", val);
this.updateFooterActions();
}
private onMaxPanelCountChanged(): void {
const val = this.maxPanelCount;
if (val < this.minPanelCount) this.minPanelCount = val;
if (this.panelCount > val) this.panelCount = val;
this.updateFooterActions();
}
/**
* Specifies whether users are allowed to add new panels.
Expand Down Expand Up @@ -1771,6 +1779,12 @@ export class QuestionPanelDynamicModel extends Question
public onSurveyLoad(): void {
this.template.readOnly = this.isReadOnly;
this.template.onSurveyLoad();
if(this.panelCount < this.minPanelCount) {
this.panelCount = this.minPanelCount;
}
if(this.panelCount > this.maxPanelCount) {
this.panelCount = this.maxPanelCount;
}
this.buildPanelsFirstTime();
super.onSurveyLoad();
}
Expand Down
25 changes: 25 additions & 0 deletions packages/survey-core/tests/question_paneldynamic_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7472,4 +7472,29 @@ QUnit.test("defaultRowValue in dynamic panel, Bug#8819", function (assert) {
panel.panels[1].questions[0].addRow();
assert.deepEqual(panel.value, [{ matrix1: [{ "col1": "abc" }] }, { matrix1: [{ "col1": "abc" }, { "col1": "abc" }] }], "#3");
});
QUnit.test("maxRowCount & footer buttons, Bug#8865", function (assert) {
const survey = new SurveyModel({
"elements": [
{
"type": "paneldynamic",
"name": "panel1",
"templateElements": [
{
"type": "text",
"name": "q1"
}
]
}
]
});
const panel = <QuestionPanelDynamicModel>survey.getQuestionByName("panel1");
const btnAdd = panel.footerToolbar.getActionById("sv-pd-add-btn");
assert.equal(btnAdd.isVisible, true, "#1");
panel.value = [{ q1: "abc" }];
assert.equal(btnAdd.isVisible, true, "#2");
panel.maxPanelCount = 1;
assert.equal(btnAdd.isVisible, false, "#3");
panel.maxPanelCount = 2;
assert.equal(btnAdd.isVisible, true, "#4");
});

0 comments on commit d5a22e1

Please sign in to comment.