Skip to content

Commit 691f8d9

Browse files
authored
visibleIf does not work for nested Panel inside DynamicPanel when using "Show single input field per page" fix #10360 (#10368)
1 parent d09e8b3 commit 691f8d9

File tree

4 files changed

+61
-17
lines changed

4 files changed

+61
-17
lines changed

packages/survey-core/src/panel.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -699,28 +699,29 @@ export class PanelModelBase extends SurveyElement<Question>
699699
*/
700700
public get questions(): Array<Question> {
701701
if (!this.isQuestionsReady) {
702-
this.questionsValue = [];
703-
for (var i = 0; i < this.elements.length; i++) {
704-
var el = this.elements[i];
705-
if (el.isPanel) {
706-
var qs = (<PanelModel>el).questions;
707-
for (var j = 0; j < qs.length; j++) {
708-
this.questionsValue.push(qs[j]);
709-
}
710-
} else {
711-
this.questionsValue.push(<Question>el);
712-
}
713-
}
702+
this.questionsValue = this.getQuestionsCore(false);
714703
this.isQuestionsReady = true;
715704
}
716705

717706
return this.questionsValue;
718707
}
719708
public get visibleQuestions(): Array<Question> {
709+
return this.getQuestionsCore(true);
710+
}
711+
private getQuestionsCore(isVisible: boolean): Array<Question> {
720712
const res = new Array<Question>();
721-
this.questions.forEach(q => {
722-
if (q.isVisible) res.push(q);
723-
});
713+
for (let i = 0; i < this.elements.length; i++) {
714+
const el = this.elements[i];
715+
if (isVisible && !el.isVisible) continue;
716+
if (el.isPanel) {
717+
var qs = (<PanelModel>el).getQuestionsCore(isVisible);
718+
for (let j = 0; j < qs.length; j++) {
719+
res.push(qs[j]);
720+
}
721+
} else {
722+
res.push(<Question>el);
723+
}
724+
}
724725
return res;
725726
}
726727
public getQuestions(includeNested: boolean): Array<Question> {

packages/survey-core/src/question_paneldynamic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ export class QuestionPanelDynamicModel extends Question
12411241
}
12421242
private fillSingleInputQuestionsByPanel(res: Array<Question>, panel: PanelModel): void {
12431243
if (panel) {
1244-
panel.questions.forEach(q => q.addNestedQuestion(res, true, false, false));
1244+
panel.visibleQuestions.forEach(q => q.addNestedQuestion(res, true, false, false));
12451245
}
12461246
}
12471247
protected getSingleQuestionLocTitleCore(): LocalizableString {

packages/survey-core/src/survey.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7758,7 +7758,7 @@ export class SurveyModel extends SurveyElementCore
77587758
public calculateWidthMode(): string {
77597759
if (this.widthMode == "auto") {
77607760
let isResponsive = false;
7761-
if (this.questionsOnPageMode != "inputPerPage") {
7761+
if (!this.isSingleVisibleInput) {
77627762
this.pages.forEach((page) => {
77637763
if (page.needResponsiveWidth())
77647764
isResponsive = true;

packages/survey-core/tests/inputPerPageTests.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,6 +2285,49 @@ QUnit.test("singleInput navigattion & errors for nested matrix #4, Bug#9982", as
22852285
assert.equal(matrix.singleInputQuestion.name, "employee-name", "singleInputQuestion is employee-name, #5");
22862286
assert.equal(matrix.singleInputQuestion.errors.length, 1, "singleInputQuestion show errors, #5");
22872287
});
2288+
QUnit.test("singleInput visibleIf in the container in dynamic panel, Bug#10360", assert => {
2289+
const survey = new SurveyModel({
2290+
elements: [
2291+
{ type: "paneldynamic", name: "panel", panelCount: 2, templateElements: [
2292+
{ type: "text", name: "q1", isRequired: true, defaultValue: "a" },
2293+
{ type: "panel", name: "p1", visibleIf: "{panel.q1} = 'a'",
2294+
elements: [{ type: "text", name: "q2", isRequired: true }]
2295+
}
2296+
]
2297+
}
2298+
],
2299+
questionsOnPageMode: "inputPerPage"
2300+
});
2301+
const panel = <QuestionPanelDynamicModel>survey.getQuestionByName("panel");
2302+
assert.equal(survey.currentSingleQuestion.name, "panel", "currentSingleQuestion is panel, #1");
2303+
assert.equal(panel.singleInputQuestion.name, "q1", "singleInputQuestion is q1, #1");
2304+
survey.performNext();
2305+
assert.equal(panel.singleInputQuestion.name, "q2", "singleInputQuestion is q2, #2");
2306+
survey.performPrevious();
2307+
assert.equal(panel.singleInputQuestion.name, "q1", "singleInputQuestion is q1, #3");
2308+
assert.equal(panel.panels[0].getElementByName("p1").isVisible, true, "p1 is visible, #3");
2309+
panel.singleInputQuestion.value = "b";
2310+
assert.equal(panel.panels[0].getElementByName("p1").isVisible, false, "p1 is not visible, #4");
2311+
assert.equal(panel.panels[0].getQuestionByName("q2").isVisibleInSurvey, false, "q2 is not visible, #4");
2312+
survey.performNext();
2313+
assert.equal(panel.singleInputQuestion.name, "q1", "singleInputQuestion is q1, #4");
2314+
survey.performNext();
2315+
assert.equal(panel.singleInputQuestion.name, "q2", "singleInputQuestion is q2, #5");
2316+
panel.singleInputQuestion.value = "val1";
2317+
survey.performNext();
2318+
assert.equal(panel.singleInputQuestion.name, "panel", "singleInputQuestion is panel - summary, #6");
2319+
panel.singleInputSummary?.items[1].btnEdit.action();
2320+
assert.equal(panel.singleInputQuestion.name, "q1", "singleInputQuestion is q1, #7");
2321+
panel.singleInputQuestion.value = "b";
2322+
survey.performNext();
2323+
assert.equal(panel.singleInputQuestion.name, "panel", "singleInputQuestion is panel, #8");
2324+
panel.singleInputSummary?.items[1].btnEdit.action();
2325+
assert.equal(panel.singleInputQuestion.name, "q1", "singleInputQuestion is q1, #9");
2326+
panel.singleInputQuestion.value = "a";
2327+
survey.performNext();
2328+
assert.equal(panel.singleInputQuestion.name, "q2", "singleInputQuestion is q2, #10");
2329+
});
2330+
22882331
//TODO re-think this test. We need to include summaries into brasdscrum navigation
22892332
QUnit.skip("singleInput bradscrum navigation for 3 level dynamic panels", assert => {
22902333
const survey = new SurveyModel({

0 commit comments

Comments
 (0)