Skip to content

Commit 6b44e39

Browse files
committed
Fix validator messages interpolation
1 parent 267073c commit 6b44e39

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

dev/full/schema.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ module.exports = {
7676
styleClasses: "half-width",
7777
validator: validators.string.locale({
7878
fieldIsRequired: "The password is required!",
79-
textTooSmall: "Password must be at least {1} characters"
79+
textTooSmall: "Password must be at least {1} characters!"
8080
})
8181
}, {
8282
type: "input",

src/utils/validators.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function checkEmpty(value, required, messages = resources) {
4646
function msg(text) {
4747
if (text != null && arguments.length > 1)
4848
for (let i = 1; i < arguments.length; i++)
49-
text = text.replace(/\{\d+?\}/, arguments[i]);
49+
text = text.replace("{" + (i - 1) + "}", arguments[i]);
5050

5151
return text;
5252
}

test/unit/specs/utils/validators.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,10 @@ describe("Validators", () => {
420420

421421
it("should give the localized error message", () => {
422422
v.resources.fieldIsRequired = "A mezőt kötelező kitölteni!";
423-
v.resources.textTooSmall = "A szöveg túl rövid. {1} helyett {0}";
423+
v.resources.textTooSmall = "A szöveg túl rövid. Minimum {1} a {0} helyett";
424424

425425
expect(v.number(null, field)[0]).to.be.equal("A mezőt kötelező kitölteni!");
426-
expect(v.string("Ab", field)[0]).to.be.equal("A szöveg túl rövid. 2 helyett 5");
426+
expect(v.string("Ab", field)[0]).to.be.equal("A szöveg túl rövid. Minimum 5 a 2 helyett");
427427
});
428428

429429
});

0 commit comments

Comments
 (0)