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?
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?
@admin055 definetely
Perfect, thanks for the confirmation. I'll toy with Malli in a project and see how to organize this. 👍
is there an example demo project with form validation somewhere?
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.
What do you think?
sure, examples welcome! I have a malli-form (reagent) demo draft, but nothing serious.
Perfect, let's do this!
<https://github.com/dharrigan/startrek>
has form validation
<https://github.com/dharrigan/startrek/blob/master/src/startrek/base/api/starship/specs.clj>
used here <https://github.com/dharrigan/startrek/blob/master/src/startrek/base/api/starship/routes.clj>
Awesome, thanks @dharrigan!
you're most welcome
hi, Anyone know if Malli has support that allows you to set a default value if the value doesn't pass the schema check?
You mean this? <https://github.com/metosin/malli#default-values>
possibly. Generally I just want to check a map is valid but keep any good values and log out any errors
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 errorshi! 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
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.
small change, clears thing a lot.
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)