From cbb0ccf1e37a3177a6835bb7f2f5978ea1e56817 Mon Sep 17 00:00:00 2001 From: tsv2013 Date: Wed, 19 Jun 2024 12:37:22 +0300 Subject: [PATCH] Fixed https://github.com/surveyjs/survey-creator/issues/5578 - The creator.onModified event is not raised when modifying individual Mask Settings (#8437) * Fixed https://github.com/surveyjs/survey-creator/issues/5578 - The creator.onModified event is not raised when modifying individual Mask Settings * Fixed build --------- Co-authored-by: tsv2013 --- src/mask/mask_base.ts | 11 ++++++++-- src/question_text.ts | 1 + tests/mask/mask_settings_tests.ts | 35 +++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/mask/mask_base.ts b/src/mask/mask_base.ts index b85d913886..f55baf3b1b 100644 --- a/src/mask/mask_base.ts +++ b/src/mask/mask_base.ts @@ -1,4 +1,5 @@ import { Base } from "../base"; +import { ISurvey } from "../base-interfaces"; import { JsonObject, Serializer, property } from "../jsonobject"; import { IInputMask, IMaskedInputResult, ITextInputParams } from "./mask_utils"; @@ -18,6 +19,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"; } @@ -34,7 +41,7 @@ export class InputMaskBase extends Base implements IInputMask { const properties = Serializer.getProperties(this.getType()); properties.forEach(property => { const currentValue = (this as any)[property.name]; - if(!property.isDefaultValue(currentValue)) { + if (!property.isDefaultValue(currentValue)) { res[property.name] = currentValue; } }); @@ -56,7 +63,7 @@ Serializer.addClass( [ { name: "saveMaskedValue:boolean", - visibleIf: function(obj: any) { + visibleIf: function (obj: any) { if (!obj) return false; return obj.getType() !== "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