DanFMoore / react-validatorjs-strategy

Strategy for using validatorjs with react-validation-mixin
The Unlicense
10 stars 5 forks source link

Add test language. #9

Open BondarenkoAlex opened 7 years ago

DanFMoore commented 7 years ago

Right, I think I see what's happened. On validatorjs 2.0.5, my method in the docs worked for setting the language worked. This kind of thing:

function (validator) {
    validator.lang = 'ru';
}

Because of the update to 3.9 in master now, that no longer works. But because this is a change to API of validatorjs, I don't think the way you've done it to support the old method is the right way. If users check the documentation of validatorjs to see what methods or attributes to set in the callback, they won't see the lang attribute listed.

Instead it looks like the proper way to do it in validatorjs is this way:

Validator.useLang('es');

It doesn't look like you can set the language on a specific validator instance anymore as it's a static method so I might just update the documentation to reflect that although that is going slightly into documenting validatorjs which I don't really want to do. The language example for the callback was only ever intended as an example to show how the instance could be manipulated after creation.

It actually looks like there are no instance methods / attributes in validatorjs now (apart from passes() and fails()) so I'm not even sure if the callback is needed anymore.

BondarenkoAlex commented 7 years ago

Yes, I agree that to call the prototype method in instance is wrong. This leads to a mess in the procedure .

But it is important to give a chance to change the language from English to any other language.

My question is what is the best way to do it? Maybe we can do it like this: strategy.setDefaultLang('ru'); ?