Skip to content

Commit 21f368d

Browse files
authored
DateTime Mask - Display Format is not applied when using "defaultValueExpression": "today()" fix #11158 (#11159)
* DateTime Mask - Display Format is not applied when using "defaultValueExpression": "today()" fix #11158 * Update test name for datetime mask with defaultValueExpression to include bug reference #11158
1 parent 6e589ab commit 21f368d

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

packages/survey-core/src/question_text.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,11 @@ export class QuestionTextModel extends QuestionTextBase {
505505
}
506506
protected convertFuncValuetoQuestionValue(val: any): any {
507507
let type = this.maskTypeIsEmpty ? this.inputType : this.maskSettings.getTypeForExpressions();
508-
return Helpers.convertValToQuestionVal(val, type);
508+
const res = Helpers.convertValToQuestionVal(val, type);
509+
if (!this.maskTypeIsEmpty && this.maskSettings.saveMaskedValue && typeof res === "string") {
510+
return this.maskInstance.getMaskedValue(res);
511+
}
512+
return res;
509513
}
510514
private getMinMaxErrorText(errorText: string, value: any): string {
511515
if (Helpers.isValueEmpty(value)) return errorText;

packages/survey-core/tests/mask/mask_datetime_tests.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,4 +1352,29 @@ QUnit.test("Mask datetime with defaultValue includes seconds, #10820", function
13521352
});
13531353
const q1 = <QuestionTextModel>survey.getQuestionByName("q1");
13541354
assert.equal(q1.inputValue, "09/04/2024 12:34:56");
1355+
});
1356+
1357+
QUnit.test("Mask datetime with defaultValueExpression today() and saveMaskedValue, Bug#11158", function (assert) {
1358+
function todayMock() {
1359+
return new Date(2025, 3, 10);
1360+
}
1361+
FunctionFactory.Instance.register("todayMock", todayMock);
1362+
const survey = new SurveyModel({
1363+
elements: [
1364+
{
1365+
type: "text",
1366+
name: "date1",
1367+
defaultValueExpression: "todayMock()",
1368+
maskType: "datetime",
1369+
maskSettings: {
1370+
saveMaskedValue: true,
1371+
pattern: "dd.mm.yyyy"
1372+
}
1373+
},
1374+
]
1375+
});
1376+
const q1 = <QuestionTextModel>survey.getQuestionByName("date1");
1377+
assert.equal(q1.inputValue, "10.04.2025", "inputValue is masked");
1378+
assert.equal(q1.value, "10.04.2025", "value is saved as masked");
1379+
FunctionFactory.Instance.unregister("todayMock");
13551380
});

0 commit comments

Comments
 (0)