Fork me on GitHub
#malli
<
2021-05-20
>
Michaël Salihi09:05:53

Hi! Is Malli a good candidate to use for server side form validation in replacement for lib like https://funcool.github.io/struct/latest/? Especially thanks to malli.error / humanize?

Michaël Salihi09:05:35

With some hand made regex validators (email, etc) like https://github.com/funcool/struct/blob/master/src/struct/core.cljc#L195 + locale support, I think so, right?

Michaël Salihi09:05:28

Perfect, thanks for the confirmation. I'll toy with Malli in a project and see how to organize this. 👍

Michaël Salihi09:05:42

is there an example demo project with form validation somewhere?

Michaël Salihi09:05:01

I like very much the Reitit's example folder, if my tests are successful after a code review, I may be able to contribute with an example PR with form validation on Malli's Github.

Michaël Salihi09:05:41

What do you think?

ikitommi10:05:47

sure, examples welcome! I have a malli-form (reagent) demo draft, but nothing serious.

Michaël Salihi10:05:15

Perfect, let's do this!

dharrigan10:05:50

has form validation

dharrigan10:05:31

you're most welcome

👍 5
shan16:05:33

hi, Anyone know if Malli has support that allows you to set a default value if the value doesn't pass the schema check?

dharrigan16:05:28

You mean this?

shan16:05:00

looks like that just sets a default if the value is missing:

(m/parse
 [:and {:default 42} int?]
 "test");; => :malli.core/invalid


(m/decode [:and {:default 42} int?]
          "test"
          mt/default-value-transformer);; => "test"
I'll probably just use m/explain and do something based on if there are errors

ikitommi04:05:26

might not be simple as any fix could change the conditional branch that should be used (with :or and :multi). But you should be able to use malli.util functions to access the invalid paths and work from there.

👍 2
shan16:05:19

possibly. Generally I just want to check a map is valid but keep any good values and log out any errors

Vladislav18:05:10

hi! Deref of [:merge ...] makes :registry with nested schemas of one of merged schemas invisible (but it still works). is it a bug, or feature, or there is some workaround Im missing? point is - registry disappears from any of serialisations after deref, although it contains all information about recursive fields, and i assume there is no other way of define recursive schemas. of course, i still could use underefed schema, but it much complicated

ikitommi18:05:05

Can't recall where it was discussed, but we should clearly separate the locally registered schemas from normal registered ones and with the malli.util fns, expose the accumulated local registry, to be used in schema form. This makes the schemas visible and thus, serializable.

ikitommi18:05:26

small change, clears thing a lot.

Vladislav19:05:15

I tried to find some way of extract and then serialize registry from schema (`m/-registry`, and then malli.registry/schemas ), but sadly unsuccess - it still needs more class serialization (may be to deref every schema from it? - leave it for tomorrow)