making main form better.
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
(defn builder [{:keys [can-submit data-sub change-event submit-event id fullwidth?] :as z}]
|
||||
(let [data-sub (or data-sub [::forms/form id])
|
||||
change-event (or change-event [::forms/change id])
|
||||
{:keys [data error]} @(re-frame/subscribe data-sub)
|
||||
{:keys [data error] form-key :id} @(re-frame/subscribe data-sub)
|
||||
status @(re-frame/subscribe [::status/single id])]
|
||||
(r/create-element Provider #js {:value #js {:can-submit @(re-frame/subscribe can-submit)
|
||||
:change-event change-event
|
||||
@@ -29,6 +29,7 @@
|
||||
:data data
|
||||
:fullwidth? fullwidth?}}
|
||||
(r/as-element
|
||||
^{:key form-key}
|
||||
[:form {:on-submit (fn [e]
|
||||
(when (.-stopPropagation e)
|
||||
(.stopPropagation e)
|
||||
@@ -78,13 +79,19 @@
|
||||
(into [:div.control ] children)]))]))
|
||||
|
||||
(defn field []
|
||||
(let [[label child] (r/children (r/current-component))]
|
||||
(let [props (r/props (r/current-component))
|
||||
[label child] (r/children (r/current-component))]
|
||||
[:> Consumer {}
|
||||
(fn [consume]
|
||||
(r/as-element
|
||||
[:div.field
|
||||
(when label (if (aget consume "fullwidth?") [:p.help label]
|
||||
[:label.label label]))
|
||||
(when label
|
||||
(if (aget consume "fullwidth?")
|
||||
[:p.help label]
|
||||
[:label.label
|
||||
(if (:required? props)
|
||||
[:span label [:span.has-text-danger " *"]]
|
||||
label)]))
|
||||
[:div.control [raw-field {} child]]]))]))
|
||||
|
||||
(defn horizontal-control []
|
||||
@@ -111,7 +118,7 @@
|
||||
(into [:div {:style {:margin-bottom "5em"}}]
|
||||
(r/children (r/current-component)))])
|
||||
|
||||
(defn submit-button []
|
||||
(defn submit-button [{:keys [class]}]
|
||||
(let [[child] (r/children (r/current-component))]
|
||||
[:> Consumer {}
|
||||
(fn [consume]
|
||||
@@ -121,8 +128,9 @@
|
||||
(r/as-element
|
||||
[:button.button.is-medium.is-primary {:disabled (or (status/disabled-for status)
|
||||
(not can-submit))
|
||||
:class (cond-> (status/class-for status)
|
||||
fullwidth? (conj "is-fullwidth")) }
|
||||
:class (cond-> (or class [])
|
||||
(status/class-for status) (conj (status/class-for status))
|
||||
fullwidth? (conj "is-fullwidth")) }
|
||||
child])))]))
|
||||
|
||||
(defn hidden-submit-button []
|
||||
|
||||
Reference in New Issue
Block a user