Skip to content

Commit

Permalink
Fixed surveyjs/survey-creator#5578 - The creator.onModified event is …
Browse files Browse the repository at this point in the history
…not raised when modifying individual Mask Settings (#8437)

* Fixed surveyjs/survey-creator#5578 - The creator.onModified event is not raised when modifying individual Mask Settings

* Fixed build

---------

Co-authored-by: tsv2013 <tsv2013@noreply.github.com>
  • Loading branch information
tsv2013 and tsv2013 authored Jun 19, 2024
1 parent 3191413 commit cbb0ccf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/mask/mask_base.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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";
}
Expand All @@ -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;
}
});
Expand All @@ -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";
},
Expand Down
1 change: 1 addition & 0 deletions src/question_text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export class QuestionTextModel extends QuestionTextBase {
maskClassName = "masksettings";
}
const inputMask = Serializer.createClass(maskClassName);
inputMask.owner = this.survey;
return inputMask;
}

Expand Down
35 changes: 35 additions & 0 deletions tests/mask/mask_settings_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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");
});

0 comments on commit cbb0ccf

Please sign in to comment.