Skip to content

Commit

Permalink
Fix validator messages interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Mar 23, 2017
1 parent 267073c commit 6b44e39
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dev/full/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = {
styleClasses: "half-width",
validator: validators.string.locale({
fieldIsRequired: "The password is required!",
textTooSmall: "Password must be at least {1} characters"
textTooSmall: "Password must be at least {1} characters!"
})
}, {
type: "input",
Expand Down
2 changes: 1 addition & 1 deletion src/utils/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function checkEmpty(value, required, messages = resources) {
function msg(text) {
if (text != null && arguments.length > 1)
for (let i = 1; i < arguments.length; i++)
text = text.replace(/\{\d+?\}/, arguments[i]);
text = text.replace("{" + (i - 1) + "}", arguments[i]);

return text;
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit/specs/utils/validators.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,10 @@ describe("Validators", () => {

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

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

});
Expand Down

0 comments on commit 6b44e39

Please sign in to comment.