Skip to content

Commit

Permalink
Implement onPopupVisibilityChanged event (#6427)
Browse files Browse the repository at this point in the history
* Work for surveyjs/survey-creator#4246: implement onPopupVisibilityChanged event

* Describe the event

* Rename event

* Fix u test

---------

Co-authored-by: Roman Tsukanov <roman.tsukanov@devexpress.com>
  • Loading branch information
dk981234 and Roman Tsukanov authored Jun 29, 2023
1 parent adf1257 commit 170809c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
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 @@ -2066,6 +2067,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 @@ -897,3 +898,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 @@ -776,6 +777,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 @@ -946,6 +952,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 @@ -7023,6 +7032,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 @@ -17181,3 +17181,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");
});

0 comments on commit 170809c

Please sign in to comment.