Skip to content

Commit

Permalink
Merge pull request #9335 from surveyjs/bug/9268-mask-displayvalue
Browse files Browse the repository at this point in the history
Questions with mask should used mask properties on returning displayV…
  • Loading branch information
andrewtelnov authored Jan 18, 2025
2 parents aa9a669 + e4669cf commit 584d637
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/survey-core/src/question_text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ export class QuestionTextModel extends QuestionTextBase {
this.setRenderedMinMax(values, properties);
}
}

protected getDisplayValueCore(keysAsText: boolean, value: any): any {
if (!this.maskTypeIsEmpty && !Helpers.isValueEmpty(value)) return this.maskInstance.getMaskedValue(value);
return super.getDisplayValueCore(keysAsText, value);
}
isLayoutTypeSupported(layoutType: string): boolean {
return true;
}
Expand Down
28 changes: 28 additions & 0 deletions packages/survey-core/tests/question_texttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,4 +569,32 @@ QUnit.test("Mask pattern default inputValue", function (assert) {
});
const q1 = <QuestionTextModel>survey.getQuestionByName("q1");
assert.equal(q1.inputValue, "_");
});
QUnit.test("Support mask in displayValue, #9268", function (assert) {
const survey = new SurveyModel({
elements: [
{
type: "text",
name: "q1",
maskType: "numeric",
maskSettings: {
decimalSeparator: ",",
thousandsSeparator: " ",
},
},
{ type: "text", name: "q2", title: "Title: {q1}" }
]
});
const q1 = <QuestionTextModel>survey.getQuestionByName("q1");
const q2 = survey.getQuestionByName("q2");
assert.equal(q1.displayValue, "", "displayValue #1");
assert.equal(q2.locTitle.textOrHtml, "Title: ", "title #1");
q1.value = 1234567.3;
assert.equal(q1.displayValue, "1 234 567,3", "displayValue #2");
assert.equal(q2.locTitle.textOrHtml, "Title: 1 234 567,3", "title #2");
assert.equal(q1.getDisplayValue(false, 1234), "1 234", "getDisplayValue with value #1");
q1.maskSettings.saveMaskedValue = true;
assert.equal(q1.getDisplayValue(false, 1234), "1 234", "getDisplayValue with value #2");
assert.equal(q1.value, 1234567.3, "Have the same value");
assert.equal(q1.inputValue, "1 234 567,3", "Have the same input value");
});

0 comments on commit 584d637

Please sign in to comment.