Fork me on GitHub
#clojure-spec
<
2017-10-17
>
talgiat05:10:55

Are there ways to validate a form with spec, with user friendly error messages (not developer friendly). I’ve found this: https://github.com/alexanderkiel/phrase but I don’t want to do field by field validation but validate a whole spec that is a map with field dependent error messages.

bbrinck13:10:29

Can you talk more about the map of fields? Do you have an example?

seancorfield06:10:36

@talgiat See if this might be closer to what you want https://github.com/bhb/expound

tatut12:10:23

how do I override a generator for something thats deep within some nested maps, without doing s/def on that thing?

tatut12:10:31

am I missing something

alexmiller13:10:27

You can override by path

alexmiller13:10:46

But it is tricky to find exactly the right path to use

taylor22:10:04

do you need the same spec to work for both those test cases, or just the first?

taylor22:10:04

clojure
(s/def ::field
  (s/cat :field-name string?
         :field-type #{'Currency 'Text}))
(s/def ::entity
  (s/cat :entity-name keyword?
         :fields (s/+ (s/spec ::field))))
(s/valid? ::entity '(:columns ("Price" Currency) ("Description" Text)))
;;=> true

taylor22:10:38

could replace s/+ with s/* if you don’t require anything after the initial keyword

fenton22:10:49

Just the first

fenton22:10:29

Ok I'll try that thanks