some specs, checkbox support

integration-tests
Josha von Gizycki 6 years ago
parent 5fe5ed5239
commit 4aa80950e5

@ -10,6 +10,8 @@
string? string?
#(some #{"date" "file" "string" "text"} %))) #(some #{"date" "file" "string" "text"} %)))
(spec/def ::required boolean?)
(neo4j/defquery (neo4j/defquery
findy-by-schema findy-by-schema
"MATCH (a:attribute)-->(s:schema) "MATCH (a:attribute)-->(s:schema)

@ -54,9 +54,7 @@
(defn drop-down (defn drop-down
([form-def field req] ([form-def field req]
{:pre [(spec/valid? ::form form-def)]} {:pre [(spec/valid? ::form form-def)]}
(drop-down form-def (drop-down form-def field req
field
req
(get-in form-def [:fields field :options]))) (get-in form-def [:fields field :options])))
([form-def field req options] ([form-def field req options]
{:pre [(spec/valid? ::form form-def)]} {:pre [(spec/valid? ::form form-def)]}
@ -71,6 +69,19 @@
options options
field-value))))) field-value)))))
(defn check-box [form-def field req]
{:pre [(spec/valid? ::form form-def)]}
(let [field-value (get-in req [:params field])
field-def (get-in form-def [:fields field])
{:keys [label required] spec-key :spec} field-def]
(list
(when-not (field-valid? field-value spec-key req)
(spec-to-errmsg label spec-key field-value))
(hform/label field label)
(hform/check-box field
(some? field-value)
field-value))))
(defn valid? [form-def req] (defn valid? [form-def req]
{:pre [(spec/valid? ::form form-def)]} {:pre [(spec/valid? ::form form-def)]}
(reduce-kv (reduce-kv

@ -23,7 +23,10 @@
:options [["Lon e lipu" "string"] :options [["Lon e lipu" "string"]
["Ali lon e lipu" "text"] ["Ali lon e lipu" "text"]
["Kama" "date"] ["Kama" "date"]
["Sitelen" "file"]]}}}) ["Sitelen" "file"]]}
:required {:label "Wile"
:required false
:spec ::attr-domain/required}}})
(defn overview! [req] (defn overview! [req]
(let [session (:session req) (let [session (:session req)
@ -72,6 +75,7 @@
(hform/hidden-field "schema" (:uuid schema)) (hform/hidden-field "schema" (:uuid schema))
(form/field new-attr-form :name req) (form/field new-attr-form :name req)
(form/drop-down new-attr-form :type req) (form/drop-down new-attr-form :type req)
(form/check-box new-attr-form :required req)
(hform/submit-button "Pali")) (hform/submit-button "Pali"))
[:h2 "Mute pali"] [:h2 "Mute pali"]
(hform/form-to (hform/form-to

Loading…
Cancel
Save