friemen / examine

Validating Clojure(Script) data.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adding custom messages to failed constraints

OliverM opened this issue · comments

From the docs & source, it looks like to add custom messages you need to use a localizer that accepts constraint messages as keys and human-readable messages as values. It also looks like you can use the key as a way to further customize those messages (so instead of a generic "Value must not be blank" you could have "First name must not be blank", with the text varying by each blank field found.

Is this all how you'd suggest doing something like generating the "First name must not be blank" report?

I often have situations where some fields can't be blank for different reasons than others, or that I'd want different warning text for the same validation error. Is there a way to specify directly as part of the constraint? Something like:

(defvalidator blanks test-data 
  :firstname [required "First name is required; initials are enough!"]
  :surname required ;; no need for custom msg
  :age [required "Please supply an age. You can't use this service if you are under 13 years old."])

Or would you think the existing localization setup is best adapted to this?

I just uploaded 1.3.0-SNAPSHOT which should implement what you are asking for.
Please check if it fits your needs. If yes, I would do a proper release.

It works perfectly, thank you!

Released 1.3.0