This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-13
Channels
- # babashka (45)
- # babashka-sci-dev (15)
- # beginners (72)
- # biff (4)
- # calva (3)
- # clj-on-windows (67)
- # clj-otel (1)
- # cljfx (7)
- # clojure (74)
- # clojure-austin (1)
- # clojure-dev (4)
- # clojure-europe (6)
- # clojure-gamedev (1)
- # clojure-germany (5)
- # clojure-losangeles (6)
- # clojure-nl (3)
- # clojure-uk (6)
- # clojured (2)
- # clojurescript (42)
- # core-typed (2)
- # cursive (4)
- # emacs (18)
- # events (1)
- # fulcro (13)
- # humbleui (8)
- # introduce-yourself (2)
- # kaocha (11)
- # leiningen (5)
- # lsp (16)
- # malli (8)
- # off-topic (69)
- # pathom (38)
- # pedestal (3)
- # reagent (17)
- # releases (3)
- # shadow-cljs (10)
- # spacemacs (6)
- # sql (1)
- # tools-deps (5)
- # xtdb (20)
Hello, We are building an automatic form generator based on Malli. The form generator input is made of: • A malli schema • A structural description of the form The structure of the form is not necessarily the same as the structure of the data. Here is a example
{:schema [:map
[:username {:title "Username"} :string]
[:email {:title "Email"
:description "The business email of the user"}
:string]
[:personal [:map
[:age {:title "Age"
:description "The age of the user"} :int]]]]
:ui {:sections [{:title "General"
:fields [{:path [:username]}]}
{:title "Details"
:fields [{:path [:personal :age]}]}]}}
Now, my question is: is there a way to retrieve the schema that corresponds to a map field?
For instance the schema that correspond to the [:personal :age]
field.sure, but there can be many schemas behind a path, if there is an :and
or :or
. but if you know what you are doing, you can just the the first one, like this:
(defn schema-in [?schema path]
(let [schema (m/schema ?schema)]
(->> (mu/in->paths schema path) (first) (mu/get-in schema))))
(schema-in
[:map
[:username :string]
[:email :string]
[:personal [:map
[:age :int]]]]
[:personal :age])
; => :int
btw, just doing the same thing in a projects (again), would like to push some parts back to the library
What exactly are you doing in your project? UI generation?
yes, two cases: 1. technical ui’s for admin/prototyping, directly from malli schemas 2. having large amount of dynamic forms & rules in project(s) => need both utilities for malli-backed form components and some data-oriented generic form-markup, “the ui-schema” … looking at your example, you are doing 2 too and I know there are many others doing that, looking forward to see if there could be something reusable / shared with these.
Have you found a way to deal with :multi
?
sure, but there can be many schemas behind a path, if there is an :and
or :or
. but if you know what you are doing, you can just the the first one, like this:
(defn schema-in [?schema path]
(let [schema (m/schema ?schema)]
(->> (mu/in->paths schema path) (first) (mu/get-in schema))))
(schema-in
[:map
[:username :string]
[:email :string]
[:personal [:map
[:age :int]]]]
[:personal :age])
; => :int