Skip to content

Commit 692c49c

Browse files
authored
Allow to hide summary table in single input mode fix #10435 (#10450)
* Allow to hide summary table in single input mode fix #10435 * Rename event
1 parent 56a7118 commit 692c49c

File tree

5 files changed

+56
-11
lines changed

5 files changed

+56
-11
lines changed

packages/survey-core/src/base-interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export interface ISurvey extends ITextProcessor, ISurveyErrorOwner {
116116
updateNavigationElements(): void;
117117
currentSingleElement: IElement;
118118
supportsNestedSingleInput(question: IQuestion): boolean;
119+
updateNestedSingleQuestions(question: IQuestion, nestedQuestions: Array<IQuestion>): void;
119120
areEmptyElementsHidden: boolean;
120121
isLoadingFromJson: boolean;
121122
isUpdateValueTextOnTyping: boolean;

packages/survey-core/src/question.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,12 @@ export class Question extends SurveyElement<Question>
10851085
}
10861086
public getSingleInputAddText(): string {
10871087
const q = this.currentSingleInputQuestion;
1088-
return !!q && !!q.singleInputSummary ? q.getSingleInputAddTextCore() : undefined;
1088+
if (!q) return undefined;
1089+
if (!!q.singleInputSummary) return q.getSingleInputAddTextCore();
1090+
const qs = this.getSingleInputQuestions();
1091+
const len = Array.isArray(qs) ? qs.length : 0;
1092+
if (len > 0 && qs[len - 1] === q) return this.getSingleInputAddTextCore();
1093+
return undefined;
10891094
}
10901095
public singleInputAddItem(checkErrors?: boolean): void {
10911096
if (!checkErrors || this.validateSingleInput()) {
@@ -1206,6 +1211,9 @@ export class Question extends SurveyElement<Question>
12061211
const question = this.getPropertyValue("singleInputQuestion");
12071212
if (question === this) return [this];
12081213
const res = this.getSingleInputQuestionsCore(question, !question || !this.isSingleInputSummaryShown);
1214+
if (this.survey) {
1215+
this.survey.updateNestedSingleQuestions(this, res);
1216+
}
12091217
res.forEach(q => { if (q !== this)this.onSingleInputQuestionAdded(q); });
12101218
return res;
12111219
}

packages/survey-core/src/survey-events-api.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IAction } from "./actions/action";
22
import { Base } from "./base";
3-
import { IDropdownMenuOptions, IElement, IPanel, ISurveyElement, IValueItemCustomPropValues } from "./base-interfaces";
3+
import { IDropdownMenuOptions, IElement, IPanel, IQuestion, ISurveyElement, IValueItemCustomPropValues } from "./base-interfaces";
44
import { ItemValue } from "./itemvalue";
55
import { PageModel } from "./page";
66
import { PanelModel, PanelModelBase } from "./panel";
@@ -1102,6 +1102,9 @@ export interface GetExpressionDisplayValueEvent extends GetQuestionDisplayValueE
11021102
export interface CheckSingleInputPerPageModeEvent extends QuestionEventMixin {
11031103
enabled: boolean;
11041104
}
1105+
export interface GetLoopQuestionsEvent extends QuestionEventMixin {
1106+
nestedQuestions: Array<Question>;
1107+
}
11051108

11061109
export interface MultipleTextItemAddedEvent extends QuestionEventMixin {
11071110
/**

packages/survey-core/src/survey.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,9 @@ import {
6767
DynamicPanelItemValueChangedEvent, DynamicPanelValueChangedEvent, DynamicPanelValueChangingEvent,
6868
DynamicPanelGetTabTitleEvent, DynamicPanelCurrentIndexChangedEvent, CheckAnswerCorrectEvent, DragDropAllowEvent, ScrollToTopEvent, GetQuestionTitleActionsEvent,
6969
GetPanelTitleActionsEvent, GetPageTitleActionsEvent, GetPanelFooterActionsEvent, GetMatrixRowActionsEvent, GetExpressionDisplayValueEvent, CheckSingleInputPerPageModeEvent,
70-
ServerValidateQuestionsEvent, MultipleTextItemAddedEvent, MatrixColumnAddedEvent, GetQuestionDisplayValueEvent, PopupVisibleChangedEvent, ChoicesSearchEvent,
71-
OpenFileChooserEvent, OpenDropdownMenuEvent, ResizeEvent,
72-
GetTitleActionsEventMixin, ProgressTextEvent, ScrollingElementToTopEvent, IsAnswerCorrectEvent,
73-
LoadChoicesFromServerEvent,
74-
ProcessTextValueEvent,
75-
CreateCustomChoiceItemEvent,
76-
MatrixRowDragOverEvent,
77-
ExpressionRunningEvent
70+
GetLoopQuestionsEvent, ServerValidateQuestionsEvent, MultipleTextItemAddedEvent, MatrixColumnAddedEvent, GetQuestionDisplayValueEvent,
71+
PopupVisibleChangedEvent, ChoicesSearchEvent, OpenFileChooserEvent, OpenDropdownMenuEvent, ResizeEvent, GetTitleActionsEventMixin, ProgressTextEvent, ScrollingElementToTopEvent,
72+
IsAnswerCorrectEvent, LoadChoicesFromServerEvent, ProcessTextValueEvent, CreateCustomChoiceItemEvent, MatrixRowDragOverEvent, ExpressionRunningEvent
7873
} from "./survey-events-api";
7974
import { QuestionMatrixDropdownModelBase } from "./question_matrixdropdownbase";
8075
import { QuestionMatrixDynamicModel } from "./question_matrixdynamic";
@@ -977,6 +972,7 @@ export class SurveyModel extends SurveyElementCore
977972
public onGetExpressionDisplayValue: EventBase<SurveyModel, GetExpressionDisplayValueEvent> = this.addEvent<SurveyModel, GetExpressionDisplayValueEvent>();
978973

979974
public onCheckSingleInputPerPageMode: EventBase<SurveyModel, CheckSingleInputPerPageModeEvent> = this.addEvent<SurveyModel, CheckSingleInputPerPageModeEvent>();
975+
public onGetLoopQuestions: EventBase<SurveyModel, GetLoopQuestionsEvent> = this.addEvent<SurveyModel, GetLoopQuestionsEvent>();
980976

981977
/**
982978
* An event that is raised after the visibility of a popup is changed.
@@ -4938,6 +4934,10 @@ export class SurveyModel extends SurveyElementCore
49384934
this.onCheckSingleInputPerPageMode.fire(this, options);
49394935
return options.enabled;
49404936
}
4937+
public updateNestedSingleQuestions(question: IQuestion, nestedQuestions: Array<IQuestion>): void {
4938+
const options: any = { question: question, nestedQuestions: nestedQuestions };
4939+
this.onGetLoopQuestions.fire(this, options);
4940+
}
49414941
private changeCurrentSingleElementOnVisibilityChanged(): void {
49424942
const el = this.currentSingleElement;
49434943
if (!el || el.isVisible) return;

packages/survey-core/tests/inputPerPageTests.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2396,4 +2396,37 @@ QUnit.skip("singleInput bradscrum navigation for 3 level dynamic panels", assert
23962396
assert.equal(actions[0].title, "Panel 2", "actions[0] title, #3");
23972397
assert.equal(actions[1].title, "Panel 2", "actions[1] title, #3");
23982398
actions[0].action();
2399-
});
2399+
});
2400+
QUnit.test("Do not show summary page on request, Issue#10435", assert => {
2401+
const survey = new SurveyModel();
2402+
survey.onGetLoopQuestions.add((_, opt) => {
2403+
const question = opt.nestedQuestions;
2404+
for (let i = question.length - 1; i >= 0; i--) {
2405+
if (question[i] === opt.question) {
2406+
question.splice(i, 1);
2407+
}
2408+
}
2409+
});
2410+
survey.fromJSON({
2411+
elements: [
2412+
{ type: "paneldynamic", name: "panel", panelCount: 1, templateElements: [
2413+
{ type: "text", name: "q1" },
2414+
{ type: "text", name: "q2" }]
2415+
},
2416+
{ type: "text", name: "q3" }
2417+
],
2418+
questionsOnPageMode: "inputPerPage"
2419+
});
2420+
const addBtn = survey.navigationBar.getActionById("sv-singleinput-add");
2421+
const panel = <QuestionPanelDynamicModel>survey.getQuestionByName("panel");
2422+
assert.equal(survey.currentSingleQuestion.name, "panel", "currentSingleQuestion is panel, #1");
2423+
assert.equal(panel.singleInputQuestion.name, "q1", "singleInputQuestion is q1, #1");
2424+
assert.equal(addBtn.visible, false, "addBtn.visible, #1");
2425+
survey.performNext();
2426+
assert.equal(panel.getSingleInputAddText(), "Add new", "getSingleInputAddText, #2");
2427+
assert.equal(panel.singleInputQuestion.name, "q2", "singleInputQuestion is q2, #2");
2428+
assert.equal(addBtn.visible, true, "addBtn.visible, #2");
2429+
survey.performNext();
2430+
assert.equal(survey.currentSingleQuestion.name, "q3", "currentSingleQuestion is q3, #3");
2431+
assert.equal(addBtn.visible, false, "addBtn.visible, #3");
2432+
});

0 commit comments

Comments
 (0)