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

Implement onPopupVisibilityChanged event #6427

Merged
merged 4 commits into from
Jun 29, 2023
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
2 changes: 2 additions & 0 deletions src/base-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { IAction } from "./actions/action";
import { PanelModel } from "./panel";
import { QuestionPanelDynamicModel } from "./question_paneldynamic";
import { DragDropAllowEvent } from "./survey-events-api";
import { PopupModel } from "./popup";

export interface ISurveyData {
getValue(name: string): any;
Expand Down Expand Up @@ -221,6 +222,7 @@ export interface ISurvey extends ITextProcessor, ISurveyErrorOwner {
runExpression(expression: string): any;
elementContentVisibilityChanged(element: ISurveyElement): void;
onCorrectQuestionAnswer(question: IQuestion, options: any): void;
processPopupVisiblityChanged(question: IQuestion, popupModel: PopupModel, visible: boolean): void;
}
export interface ISurveyImpl {
getSurveyData(): ISurveyData;
Expand Down
1 change: 1 addition & 0 deletions src/dropdownListModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class DropdownListModel extends Base {
this.resetItemsSettings();
}
}
this.question.processPopupVisiblilityChanged(this.popupModel, option.isVisible);
});
}

Expand Down
6 changes: 6 additions & 0 deletions src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { RendererFactory } from "./rendererFactory";
import { SurveyError } from "./survey-error";
import { CssClassBuilder } from "./utils/cssClassBuilder";
import { getElementWidth, increaseHeightByContent, isContainerVisible } from "./utils/utils";
import { PopupModel } from "./popup";

export interface IConditionObject {
name: string;
Expand Down Expand Up @@ -2049,6 +2050,11 @@ export class Question extends SurveyElement<Question>
getAllValues(): any {
return !!this.data ? this.data.getAllValues() : null;
}

public processPopupVisiblilityChanged(popupModel: PopupModel, visible: boolean): void {
this.survey.processPopupVisiblityChanged(this, popupModel, visible);
}

public transformToMobileView(): void { }
public transformToDesktopView(): void { }
public needResponsiveWidth() {
Expand Down
12 changes: 12 additions & 0 deletions src/survey-events-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IElement, ISurveyElement } from "./base-interfaces";
import { ItemValue } from "./itemvalue";
import { PageModel } from "./page";
import { PanelModel, PanelModelBase } from "./panel";
import { PopupModel } from "./popup";
import { Question } from "./question";
import { QuestionFileModel } from "./question_file";
import { MatrixDropdownCell, MatrixDropdownRowModelBase, QuestionMatrixDropdownModelBase } from "./question_matrixdropdownbase";
Expand Down Expand Up @@ -855,3 +856,14 @@ export interface MatrixColumnAddedEvent extends QuestionEventMixin {
*/
column: any;
}

export interface PopupVisibleChangedEvent extends QuestionEventMixin {
/**
* An object that describes the popup.
*/
popup: PopupModel;
/**
* Indicates whether the popup is visible now.
*/
visible: boolean;
}
14 changes: 13 additions & 1 deletion src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ import { ActionContainer, defaultActionBarCss } from "./actions/container";
import { CssClassBuilder } from "./utils/cssClassBuilder";
import { QuestionPanelDynamicModel } from "./question_paneldynamic";
import { Notifier } from "./notifier";
import { TriggerExecutedEvent, CompletingEvent, CompleteEvent, ShowingPreviewEvent, NavigateToUrlEvent, CurrentPageChangingEvent, CurrentPageChangedEvent, ValueChangingEvent, ValueChangedEvent, VariableChangedEvent, QuestionVisibleChangedEvent, PageVisibleChangedEvent, PanelVisibleChangedEvent, QuestionCreatedEvent, QuestionAddedEvent, QuestionRemovedEvent, PanelAddedEvent, PanelRemovedEvent, PageAddedEvent, ValidateQuestionEvent, SettingQuestionErrorsEvent, ValidatePanelEvent, ErrorCustomTextEvent, ValidatedErrorsOnCurrentPageEvent, ProcessHtmlEvent, GetQuestionTitleEvent, GetTitleTagNameEvent, GetQuestionNoEvent, ProgressTextEvent, TextMarkdownEvent, TextRenderAsEvent, SendResultEvent, GetResultEvent, UploadFilesEvent, DownloadFileEvent, ClearFilesEvent, LoadChoicesFromServerEvent, ProcessTextValueEvent, UpdateQuestionCssClassesEvent, UpdatePanelCssClassesEvent, UpdatePageCssClassesEvent, UpdateChoiceItemCssEvent, AfterRenderSurveyEvent, AfterRenderHeaderEvent, AfterRenderPageEvent, AfterRenderQuestionEvent, AfterRenderQuestionInputEvent, AfterRenderPanelEvent, FocusInQuestionEvent, FocusInPanelEvent, ShowingChoiceItemEvent, ChoicesLazyLoadEvent, GetChoiceDisplayValueEvent, MatrixRowAddedEvent, MatrixBeforeRowAddedEvent, MatrixRowRemovingEvent, MatrixRowRemovedEvent, MatrixAllowRemoveRowEvent, MatrixCellCreatingEvent, MatrixCellCreatedEvent, MatrixAfterCellRenderEvent, MatrixCellValueChangedEvent, MatrixCellValueChangingEvent, MatrixCellValidateEvent, DynamicPanelModifiedEvent, DynamicPanelRemovingEvent, TimerPanelInfoTextEvent, DynamicPanelItemValueChangedEvent, IsAnswerCorrectEvent, DragDropAllowEvent, ScrollingElementToTopEvent, GetQuestionTitleActionsEvent, GetPanelTitleActionsEvent, GetPageTitleActionsEvent, GetPanelFooterActionsEvent, GetMatrixRowActionsEvent, ElementContentVisibilityChangedEvent, GetExpressionDisplayValueEvent, ServerValidateQuestionsEvent, MultipleTextItemAddedEvent, MatrixColumnAddedEvent, GetQuestionDisplayValueEvent } from "./survey-events-api";
import { TriggerExecutedEvent, CompletingEvent, CompleteEvent, ShowingPreviewEvent, NavigateToUrlEvent, CurrentPageChangingEvent, CurrentPageChangedEvent, ValueChangingEvent, ValueChangedEvent, VariableChangedEvent, QuestionVisibleChangedEvent, PageVisibleChangedEvent, PanelVisibleChangedEvent, QuestionCreatedEvent, QuestionAddedEvent, QuestionRemovedEvent, PanelAddedEvent, PanelRemovedEvent, PageAddedEvent, ValidateQuestionEvent, SettingQuestionErrorsEvent, ValidatePanelEvent, ErrorCustomTextEvent, ValidatedErrorsOnCurrentPageEvent, ProcessHtmlEvent, GetQuestionTitleEvent, GetTitleTagNameEvent, GetQuestionNoEvent, ProgressTextEvent, TextMarkdownEvent, TextRenderAsEvent, SendResultEvent, GetResultEvent, UploadFilesEvent, DownloadFileEvent, ClearFilesEvent, LoadChoicesFromServerEvent, ProcessTextValueEvent, UpdateQuestionCssClassesEvent, UpdatePanelCssClassesEvent, UpdatePageCssClassesEvent, UpdateChoiceItemCssEvent, AfterRenderSurveyEvent, AfterRenderHeaderEvent, AfterRenderPageEvent, AfterRenderQuestionEvent, AfterRenderQuestionInputEvent, AfterRenderPanelEvent, FocusInQuestionEvent, FocusInPanelEvent, ShowingChoiceItemEvent, ChoicesLazyLoadEvent, GetChoiceDisplayValueEvent, MatrixRowAddedEvent, MatrixBeforeRowAddedEvent, MatrixRowRemovingEvent, MatrixRowRemovedEvent, MatrixAllowRemoveRowEvent, MatrixCellCreatingEvent, MatrixCellCreatedEvent, MatrixAfterCellRenderEvent, MatrixCellValueChangedEvent, MatrixCellValueChangingEvent, MatrixCellValidateEvent, DynamicPanelModifiedEvent, DynamicPanelRemovingEvent, TimerPanelInfoTextEvent, DynamicPanelItemValueChangedEvent, IsAnswerCorrectEvent, DragDropAllowEvent, ScrollingElementToTopEvent, GetQuestionTitleActionsEvent, GetPanelTitleActionsEvent, GetPageTitleActionsEvent, GetPanelFooterActionsEvent, GetMatrixRowActionsEvent, ElementContentVisibilityChangedEvent, GetExpressionDisplayValueEvent, ServerValidateQuestionsEvent, MultipleTextItemAddedEvent, MatrixColumnAddedEvent, GetQuestionDisplayValueEvent, PopupVisibleChangedEvent } from "./survey-events-api";
import { QuestionMatrixDropdownModelBase } from "./question_matrixdropdownbase";
import { QuestionMatrixDynamicModel } from "./question_matrixdynamic";
import { QuestionFileModel } from "./question_file";
import { QuestionMultipleTextModel } from "./question_multipletext";
import { ITheme } from "./themes";
import { PopupModel } from "./popup";

/**
* The `SurveyModel` object contains properties and methods that allow you to control the survey and access its elements.
Expand Down Expand Up @@ -759,6 +760,11 @@ export class SurveyModel extends SurveyElementCore
*/
public onGetExpressionDisplayValue: EventBase<SurveyModel, GetExpressionDisplayValueEvent> = this.addEvent<SurveyModel, GetExpressionDisplayValueEvent>();

/**
* An event that is raised after the visibility of a popup is changed. This event can be raised for [Single-](https://surveyjs.io/form-library/documentation/api-reference/dropdown-menu-model) and [Multi-Select Dropdown](https://surveyjs.io/form-library/documentation/api-reference/dropdown-tag-box-model) questions and [Rating](https://surveyjs.io/form-library/documentation/api-reference/rating-scale-question-model) questions [rendered as drop-down menus](https://surveyjs.io/form-library/documentation/api-reference/rating-scale-question-model#displayMode).
*/
public onPopupVisibleChanged: EventBase<SurveyModel, PopupVisibleChangedEvent> = this.addEvent<SurveyModel, PopupVisibleChangedEvent>();

//#endregion

constructor(jsonObj: any = null, renderedElement: any = null) {
Expand Down Expand Up @@ -929,6 +935,9 @@ export class SurveyModel extends SurveyElementCore
data: this.navigationBar
});
}
processClosedPopup(question: IQuestion, popupModel: PopupModel<any>): void {
throw new Error("Method not implemented.");
}
protected createTryAgainAction(): IAction {
return <IAction>{
id: "save-again",
Expand Down Expand Up @@ -6979,6 +6988,9 @@ export class SurveyModel extends SurveyElementCore
}
return containerLayoutElements;
}
public processPopupVisiblityChanged(question: Question, popup: PopupModel<any>, visible: boolean): void {
this.onPopupVisibleChanged.fire(this, { question, popup, visible });
}

public applyTheme(theme: ITheme): void {
if(!theme) return;
Expand Down
25 changes: 25 additions & 0 deletions tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17117,3 +17117,28 @@ QUnit.test("Expression with dates & defaultValueExpression & expression question
startQ.value = Helpers.convertDateToString(new Date());
checkFunc([true, true, false, false, true], 3);
});

QUnit.test("Check onPopupVisibleChanged events", function (assert) {
const survey = new SurveyModel({
elements: [
{
"type": "dropdown",
"name": "q1",
"choices": ["Item1", "Item2", "Item3"]
},
]
});
let log = "";
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const popup = question.dropdownListModel.popupModel;
survey.onPopupVisibleChanged.add((_, options) => {
assert.equal(options.question, question);
assert.equal(options.popup, popup);
log += `->${options.visible}`;
});
popup.toggleVisibility();
assert.equal(log, "->true");
popup.toggleVisibility();
assert.equal(log, "->true->false");
});