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
  • Loading branch information
tsv2013 committed Jun 18, 2024
1 parent c393f8f commit 75c3378
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/mask/mask_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
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 75c3378

Please sign in to comment.