Skip to content

Add custom replacement to custom rules - #375

Closed
felipe-gustavo wants to merge 5 commits into
mikeerickson:masterfrom
felipe-gustavo:master
Closed

felipe-gustavo wants to merge 5 commits into
mikeerickson:masterfrom
felipe-gustavo:master

Conversation

@felipe-gustavo

@felipe-gustavo felipe-gustavo commented Aug 5, 2020 •

Copy link
Copy Markdown

This will allow custom rules to add custom overrides/replacements, such as:

  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],
        };
    }
  )

Edit 1:
This will meet this requirement/issue( #136 )

This will allow custom rules to add custom overrides/replacements, such as:
```
Validator.register(
    'date_between',
    function (value, requirement) {
        // custom validation using dates
    },
    'Custom message for attribute :attribute with replacements :min and :max.',
    function (template, rule) {
        parameters = rule.getParameters();
        return {
            min: parameters[0],
            max: parameters[1],
        };
    },
)
```
Add condition if the custom replacement response not is a object to replace
@mikeerickson

Copy link
Copy Markdown
Owner

Merged

@mikeerickson mikeerickson left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a test to cover this PR. I am willing to add the PR, but will need tests to cover to make sure there is no side affect.

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

Successfully merging this pull request may close these issues.

2 participants