Skip to content

Commit

Permalink
Numeric Validator - A validation error appears with the default text …
Browse files Browse the repository at this point in the history
…rather than with the custom defined message fix #6588 (#6606)
  • Loading branch information
andrewtelnov committed Jul 27, 2023
1 parent 2c21bca commit ba730ff
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class NumericValidator extends SurveyValidator {
if (!Helpers.isNumber(value)) {
return new ValidatorResult(
null,
new RequreNumericError(null, this.errorOwner)
new RequreNumericError(this.text, this.errorOwner)
);
}
var result = new ValidatorResult(Helpers.getNumber(value));
Expand Down
30 changes: 30 additions & 0 deletions tests/surveyquestiontests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6936,4 +6936,34 @@ QUnit.test("question.getRootCss apply disable css correctly", function (assert)
assert.ok(q.cssTitle.indexOf(disableCss) > -1, "disableCss is in the title, #3");
q.readOnly = false;
assert.ok(q.cssTitle.indexOf(disableCss) === -1, "disableCss is not in the title, #4");
});
QUnit.test("numeric validator, use custom text, bug#6588", function (assert) {
const survey = new SurveyModel({
"elements": [
{
"type": "text",
"name": "q1",
"validators": [
{
"type": "numeric",
"text": "Enter only numbers"
}
]
},
{
"type": "text",
"name": "q2",
"validators": [{ "type": "numeric" }
]
}
] });
const q1 = survey.getQuestionByName("q1");
const q2 = survey.getQuestionByName("q2");
q1.value = "aa";
q2.value = "aa";
survey.hasErrors();
assert.equal(q1.errors.length, 1, "One error");
assert.equal(q1.errors[0].getText(), "Enter only numbers", "Customer error");
assert.equal(q2.errors.length, 1, "One error, #2");
assert.equal(q2.errors[0].getText(), "The value should be numeric.", "Default error");
});

0 comments on commit ba730ff

Please sign in to comment.