Fork me on GitHub
#malli
<
2022-01-18
>
coltnz20:01:08

Hi, is there a way to default a value even if the key is optional in the schema?

coltnz20:01:46

I have a map which may or may not have a date entry. In the latter case I want to default it to now

coltnz20:01:49

(m/decode [:map
           [:date {:optional true}
            [:maybe [:string {:decode/string mt/-string->date :default (tick/now)}]]]]
          {}
          (mt/transformer mt/string-transformer mt/default-value-transformer))

coltnz20:01:25

returns {} which doesn't surprise me.

Noah Bogart23:01:08

What does a default for an optional property even mean? never mind, misread and I see that you explained it