From ba730ffc5ed892b43318abb5114df2ccb1218099 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 27 Jul 2023 15:47:28 +0300 Subject: [PATCH] Numeric Validator - A validation error appears with the default text rather than with the custom defined message fix #6588 (#6606) --- src/validator.ts | 2 +- tests/surveyquestiontests.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/validator.ts b/src/validator.ts index 8f8474755f..08ff6b5107 100644 --- a/src/validator.ts +++ b/src/validator.ts @@ -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)); diff --git a/tests/surveyquestiontests.ts b/tests/surveyquestiontests.ts index 23cb90d12d..672b0e8d29 100644 --- a/tests/surveyquestiontests.ts +++ b/tests/surveyquestiontests.ts @@ -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"); }); \ No newline at end of file