diff --git a/packages/survey-core/src/survey-events-api.ts b/packages/survey-core/src/survey-events-api.ts index 8d4785f013..6387865c7d 100644 --- a/packages/survey-core/src/survey-events-api.ts +++ b/packages/survey-core/src/survey-events-api.ts @@ -62,6 +62,10 @@ export interface GetTitleActionsEventMixin { /** * An array of [actions](https://surveyjs.io/form-library/documentation/iaction) associated with the processed element. */ + actions: Array; + /** + * Obsolete. Use `options.actions` instead. + */ titleActions: Array; } export interface GetActionsEventMixin { @@ -410,7 +414,7 @@ export interface GetPageNumberEvent extends PageEventMixin { */ number: string; } -export interface ProgressTextEvent { +export interface GetProgressTextEvent { /** * The number of questions with input fields. [Image](https://surveyjs.io/form-library/examples/add-image-and-video-to-survey/), [HTML](https://surveyjs.io/form-library/examples/questiontype-html/), and [Expression](https://surveyjs.io/form-library/examples/questiontype-expression/) questions are not counted. */ @@ -432,6 +436,7 @@ export interface ProgressTextEvent { */ text: string; } +export interface ProgressTextEvent extends GetProgressTextEvent { } export interface TextProcessingEvent { /** diff --git a/packages/survey-core/src/survey.ts b/packages/survey-core/src/survey.ts index 1857be958b..a558ceb405 100644 --- a/packages/survey-core/src/survey.ts +++ b/packages/survey-core/src/survey.ts @@ -58,7 +58,7 @@ 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, GetQuestionNumberEvent, GetPageNumberEvent, ProgressTextEvent, + ErrorCustomTextEvent, ValidatedErrorsOnCurrentPageEvent, ProcessHtmlEvent, GetQuestionTitleEvent, GetTitleTagNameEvent, GetQuestionNumberEvent, GetPageNumberEvent, GetProgressTextEvent, TextMarkdownEvent, TextRenderAsEvent, SendResultEvent, GetResultEvent, UploadFilesEvent, DownloadFileEvent, ClearFilesEvent, LoadChoicesFromServerEvent, ProcessTextValueEvent, UpdateQuestionCssClassesEvent, UpdatePanelCssClassesEvent, UpdatePageCssClassesEvent, UpdateChoiceItemCssEvent, AfterRenderSurveyEvent, AfterRenderPageEvent, AfterRenderQuestionEvent, AfterRenderQuestionInputEvent, AfterRenderPanelEvent, FocusInQuestionEvent, FocusInPanelEvent, @@ -68,7 +68,8 @@ import { DynamicPanelGetTabTitleEvent, DynamicPanelCurrentIndexChangedEvent, IsAnswerCorrectEvent, DragDropAllowEvent, ScrollingElementToTopEvent, GetQuestionTitleActionsEvent, GetPanelTitleActionsEvent, GetPageTitleActionsEvent, GetPanelFooterActionsEvent, GetMatrixRowActionsEvent, GetExpressionDisplayValueEvent, ServerValidateQuestionsEvent, MultipleTextItemAddedEvent, MatrixColumnAddedEvent, GetQuestionDisplayValueEvent, PopupVisibleChangedEvent, ChoicesSearchEvent, - OpenFileChooserEvent, OpenDropdownMenuEvent, ResizeEvent + OpenFileChooserEvent, OpenDropdownMenuEvent, ResizeEvent, + GetTitleActionsEventMixin } from "./survey-events-api"; import { QuestionMatrixDropdownModelBase } from "./question_matrixdropdownbase"; import { QuestionMatrixDynamicModel } from "./question_matrixdynamic"; @@ -442,7 +443,10 @@ export class SurveyModel extends SurveyElementCore * @see showProgressBar * @see progressBarType */ - public onProgressText: EventBase = this.addEvent(); + public onGetProgressText: EventBase = this.addEvent(); + public get onProgressText(): EventBase { + return this.onGetProgressText; + } /** * An event that is raised to convert Markdown content to HTML. * @@ -967,7 +971,7 @@ export class SurveyModel extends SurveyElementCore this.onGetQuestionNumber.onCallbacksChanged = () => { this.resetVisibleIndexes(); }; - this.onProgressText.onCallbacksChanged = () => { + this.onGetProgressText.onCallbacksChanged = () => { this.updateProgressText(); }; this.onTextMarkdown.onCallbacksChanged = () => { @@ -4898,7 +4902,7 @@ export class SurveyModel extends SurveyElementCore if ( onValueChanged && this.progressBarType == "pages" && - this.onProgressText.isEmpty + this.onGetProgressText.isEmpty ) return; this.isCalculatingProgressText = true; @@ -4908,7 +4912,7 @@ export class SurveyModel extends SurveyElementCore } public getProgressText(): string { if (!this.isDesignMode && this.currentPage == null) return ""; - const options: ProgressTextEvent = { + const options: GetProgressTextEvent = { questionCount: 0, answeredQuestionCount: 0, requiredQuestionCount: 0, @@ -4920,7 +4924,7 @@ export class SurveyModel extends SurveyElementCore type === "questions" || type === "requiredquestions" || type === "correctquestions" || - !this.onProgressText.isEmpty + !this.onGetProgressText.isEmpty ) { var info = this.getProgressInfo(); options.questionCount = info.questionCount; @@ -4931,7 +4935,7 @@ export class SurveyModel extends SurveyElementCore } options.text = this.getProgressTextCore(options); - this.onProgressText.fire(this, options); + this.onGetProgressText.fire(this, options); return options.text; } private getProgressTextCore(info: IProgressInfo): string { @@ -5319,16 +5323,24 @@ export class SurveyModel extends SurveyElementCore return this.getUpdatedPanelTitleActions(element, titleActions); return this.getUpdatedQuestionTitleActions(element, titleActions); } + + private getTitleActionsResult(titleActions: Array, options: GetTitleActionsEventMixin) { + if (titleActions != options.actions) return options.actions; + if (titleActions != options.titleActions) return options.titleActions; + return titleActions; + } + private getUpdatedQuestionTitleActions( question: Question, titleActions: Array ) { const options: GetQuestionTitleActionsEvent = { question: question, + actions: titleActions, titleActions: titleActions, }; this.onGetQuestionTitleActions.fire(this, options); - return options.titleActions; + return this.getTitleActionsResult(titleActions, options); } private getUpdatedPanelTitleActions( @@ -5337,10 +5349,11 @@ export class SurveyModel extends SurveyElementCore ) { const options: GetPanelTitleActionsEvent = { panel: panel, + actions: titleActions, titleActions: titleActions, }; this.onGetPanelTitleActions.fire(this, options); - return options.titleActions; + return this.getTitleActionsResult(titleActions, options); } private getUpdatedPageTitleActions( page: PageModel, @@ -5348,10 +5361,11 @@ export class SurveyModel extends SurveyElementCore ) { var options: GetPageTitleActionsEvent = { page: page, + actions: titleActions, titleActions: titleActions, }; this.onGetPageTitleActions.fire(this, options); - return options.titleActions; + return this.getTitleActionsResult(titleActions, options); } getUpdatedMatrixRowActions( diff --git a/packages/survey-core/tests/question_paneldynamic_tests.ts b/packages/survey-core/tests/question_paneldynamic_tests.ts index e3035085fb..0cefb13f4d 100644 --- a/packages/survey-core/tests/question_paneldynamic_tests.ts +++ b/packages/survey-core/tests/question_paneldynamic_tests.ts @@ -5077,7 +5077,7 @@ QUnit.test("Bindings to panelCount performance issue #2 reduce recalc visibleInd ], }); var counter = 0; - survey.onProgressText.add((sender, options) => { + survey.onGetProgressText.add((sender, options) => { counter ++; }); counter = 0;