From 75c3378d583c103ee208455b91d41b50e9f41187 Mon Sep 17 00:00:00 2001 From: tsv2013 Date: Tue, 18 Jun 2024 18:43:00 +0300 Subject: [PATCH] Fixed https://github.com/surveyjs/survey-creator/issues/5578 - The creator.onModified event is not raised when modifying individual Mask Settings --- src/mask/mask_base.ts | 6 ++++++ src/question_text.ts | 1 + tests/mask/mask_settings_tests.ts | 35 +++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/src/mask/mask_base.ts b/src/mask/mask_base.ts index b85d913886..a118afa069 100644 --- a/src/mask/mask_base.ts +++ b/src/mask/mask_base.ts @@ -18,6 +18,12 @@ export class InputMaskBase extends Base implements IInputMask { */ @property() saveMaskedValue: boolean; + public owner: ISurvey; + + public getSurvey(live: boolean = false): ISurvey { + return this.owner as any; + } + public getType(): string { return "masksettings"; } diff --git a/src/question_text.ts b/src/question_text.ts index cf95cfc248..d307cb0d3f 100644 --- a/src/question_text.ts +++ b/src/question_text.ts @@ -100,6 +100,7 @@ export class QuestionTextModel extends QuestionTextBase { maskClassName = "masksettings"; } const inputMask = Serializer.createClass(maskClassName); + inputMask.owner = this.survey; return inputMask; } diff --git a/tests/mask/mask_settings_tests.ts b/tests/mask/mask_settings_tests.ts index 6339ad9ad9..c64511c095 100644 --- a/tests/mask/mask_settings_tests.ts +++ b/tests/mask/mask_settings_tests.ts @@ -5,6 +5,7 @@ import { InputMaskCurrency } from "../../src/mask/mask_currency"; import { QuestionTextModel } from "../../src/question_text"; import { Serializer } from "../../src/jsonobject"; import { SurveyModel } from "../../src/survey"; +import { ArrayChanges, Base } from "../../src/base"; export default QUnit.module("Question text: Input mask"); @@ -274,4 +275,38 @@ QUnit.test("isNumeric: load form data", function (assert) { assert.equal(q1.inputValue, "10 000,99"); assert.equal(q2.value, "10000.99"); assert.equal(q2.inputValue, "10 000,99"); +}); + +QUnit.test("mask settings changes trigger survey.onPropertyValueChangedCallback", function (assert) { + const survey = new SurveyModel({ + "pages": [ + { + "name": "page1", + "elements": [ + { + "type": "text", + "name": "question1", + "maskType": "numeric", + "maskSettings": { + "thousandsSeparator": "." + } + } + ] + } + ] + }); + let propName = "not triggered"; + survey.onPropertyValueChangedCallback = ( + name: string, + oldValue: any, + newValue: any, + sender: Base, + arrayChanges: ArrayChanges + ) => { + propName += "->name:" + name; + }; + + const maskedQuestion = survey.getQuestionByName("question1") as QuestionTextModel; + (maskedQuestion.maskSettings as any).thousandsSeparator = "-"; + assert.equal(propName, "not triggered->name:thousandsSeparator"); }); \ No newline at end of file