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

Conversation

Projects
None yet
4 participants
@vdh
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

This comment has been minimized.

Show comment
Hide comment
@coveralls

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

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 added a commit to vdh/validate.js that referenced this pull request Oct 20, 2016

@vdh vdh referenced this pull request Oct 20, 2016

Open

Set attribute name #69

vdh added a commit to vdh/validate.js that referenced this pull request Dec 12, 2016

@coveralls

This comment has been minimized.

Show comment
Hide comment
@coveralls

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

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.

Allow custom `prettify` function to be defined via global options
Additionally, `prettiy` can be further overridden in validator options for `numericality` and `equality` validators.
@coveralls

This comment has been minimized.

Show comment
Hide comment
@coveralls

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

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.

vdh added a commit to vdh/validate.js that referenced this pull request Jan 9, 2017

@ansman ansman merged commit 1656538 into ansman:master Apr 22, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@ansman

This comment has been minimized.

Show comment
Hide comment
@ansman

ansman Apr 22, 2017

Owner

Sorry for the delay, looks good. Thanks!

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

vdh added a commit to vdh/validate.js that referenced this pull request Apr 28, 2017

Pre-release build
ansman#164 has been merged in upstream, this fork will be deprecated on the next official validate.js release
@underscore05

This comment has been minimized.

Show comment
Hide comment
@underscore05

underscore05 May 28, 2018

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

underscore05 commented May 28, 2018

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

@vdh

This comment has been minimized.

Show comment
Hide comment
@vdh

vdh Jun 1, 2018

Contributor

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

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