Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

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 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

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

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

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
@ansman
Copy link
Owner

ansman commented Apr 22, 2017

Sorry for the delay, looks good. Thanks!

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

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants