bouncer icon indicating copy to clipboard operation
bouncer copied to clipboard

:pre functions do not get nested values

Open jwr opened this issue 9 years ago • 0 comments

When nesting validation sets, functions supplied as :pre get the entire data structure passed to b/validate, not just the nested structure that they would normally get. This basically breaks their functionality.

Here's a more descriptive example:

(def billing-data
  {:country v/required
   :eu-vat-number [[v/required
                    :pre (comp countries/eu-country-codes :country)
                    :message "is required for EU countries"]]})

(def signup-data
  {:currency v/required
   :billing-data billing-data
   :account-data account-data
   ;; [...]
   })

In this example, :eu-vat-number validation will work if a billing-data map is being validated, but will not work as expected if signup-data is validated. The :pre function will get the entire signup-data map, which does not contain a :country key, therefore the :eu-vat-number validation will never run.

jwr avatar May 21 '16 17:05 jwr