Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom replacements not working for custom rules #440

Open
sanjacornelius opened this issue Oct 26, 2021 · 1 comment
Open

Custom replacements not working for custom rules #440

sanjacornelius opened this issue Oct 26, 2021 · 1 comment

Comments

@sanjacornelius
Copy link

sanjacornelius commented Oct 26, 2021

In version 3.22.1, when using the provided example for creating custom attributes the :min and :max parameters are not returned.

In doing a little investigation version 3.22.1 seems to be missing some code from PR #375 that implemented the feature. When adding back the missing code the provided example works as expected.

Not sure if it was intended and if there is a different way the custom replacements need to be implemented in this version. A little guidance would be helpful thank you in advance!

Provided Example from Docs

Validator.register(
    'date_between',
    function (value, requirement) {
      // custom validation using dates
    },
    'Custom message for attribute :attribute with replacements :min and :max.',
    function (_template, rule, _getAttributeName) {
      const parameters = rule.getParameters();
        return {
          min: parameters[0],
          max: parameters[1],
        };
    }
);
@ethaizone
Copy link

I think this happen due some mistake. As we can see that fnReplacement is exists but it's unused.

Validator.register = function (name, fn, message, fnReplacement) {
var lang = Validator.getDefaultLang();
Rules.register(name, fn);
Lang._setRuleMessage(lang, name, message);
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants