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

Define prettify via options #164

Merged
merged 1 commit into from Apr 22, 2017
Merged

Define prettify via options #164

merged 1 commit into from Apr 22, 2017

Conversation

@vdh
Copy link
Contributor

vdh commented Oct 20, 2016

The need to override validate.prettify globally is a burden for functional programming, so I added the ability to provide it via the validate/runValidations options.

Just in case anyone might need further customisation, I also made it possible to override prettify for individual numericality and equality validations via the validator options.

@coveralls
Copy link

coveralls commented Oct 20, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 6f6d776 on vdh:prettify-via-options into f42d0ac on ansman:master.

@vdh vdh mentioned this pull request Oct 20, 2016
@coveralls
Copy link

coveralls commented Dec 12, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 856d70e on vdh:prettify-via-options into ab5ad5a on ansman:master.

Additionally, `prettiy` can be further overridden in validator options for `numericality` and `equality` validators.
@coveralls
Copy link

coveralls commented Dec 12, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling f23082e on vdh:prettify-via-options into ab5ad5a on ansman:master.

@ansman ansman merged commit 1656538 into ansman:master Apr 22, 2017
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@ansman
Copy link
Owner

ansman commented Apr 22, 2017

Sorry for the delay, looks good. Thanks!

@vdh vdh deleted the vdh:prettify-via-options branch Apr 28, 2017
@underscore05
Copy link

underscore05 commented May 28, 2018

Can you please create an example on how to use this using presence?

@vdh
Copy link
Contributor Author

vdh commented Jun 1, 2018

@underscore05 The presence validator already has the option to set a custom message, I don't understand how you're relating that validator to this.

This feature allows a custom prettify function within the options of the validate call, instead of being restricted to just the global validate.prettify.

prettify handles things like attribute names, as describled here in the docs.

For example:

return validate(values, constraints, {
  prettify: function prettify(string) {
    // Do something special with `string`, like i18n
    // Otherwise, fall back to the global…
    return validate.prettify(string);
  },
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.