add attrs key to pass any html attribute to widgets

master
Josha von Gizycki 5 years ago
parent efdfe2ab62
commit 62cb81a59a

1
.gitignore vendored

@ -9,3 +9,4 @@ pom.xml.asc
/.nrepl-port
.hgignore
.hg/
*.iml

@ -19,6 +19,7 @@
#{:input :select :checkbox :textarea :mselect :hidden})
(spec/def ::from-req ifn?)
(spec/def ::to-form ::from-req)
(spec/def ::attrs (spec/map-of keyword? (fn [_] true)))
(spec/def ::field
(spec/keys :opt-un [::label
::options
@ -26,7 +27,8 @@
::from-req
::to-form
::required
::spec]))
::spec
::attrs]))
(spec/def ::fields
(spec/map-of keyword? ::field))
(spec/def ::form-specs

@ -38,7 +38,8 @@
(hform/label field-id (:label field-def))))
(defn input-widget [id def value]
(hform/text-field {:required (or (:required def) false)}
(hform/text-field (merge {:required (or (:required def) false)}
(:attrs def))
id
value))
@ -49,7 +50,8 @@
value))
(defn textarea-widget [id def value]
(hform/text-area {:required (or (:required def) false)}
(hform/text-area (merge {:required (or (:required def) false)}
(:attrs def))
id
value))
@ -59,19 +61,19 @@
value))
(defn multiselect-widget [id def value]
(let [options (:options def)]
[:select {:multiple "multiple"
:size (:size def 5)
:name (name id)
:id (name id)}
(for [option options]
[:option {:value (second option)
:selected (some? (some (partial = (second option))
value))}
(hcore/h (first option))])]))
[:select (merge {:multiple "multiple"
:size (:size def 5)
:name (name id)
:id (name id)}
(:attrs def))
(for [option (:options def)]
[:option {:value (second option)
:selected (some? (some (partial = (second option))
value))}
(hcore/h (first option))])])
(comment
(multiselect-widget :id {:options [["<>" "key"]]} {}))
(defn hidden-widget [id def value]
(defn hidden-widget [id _ value]
(hform/hidden-field id value))

Loading…
Cancel
Save