Simplified forms considerably
This commit is contained in:
@@ -18,23 +18,26 @@
|
||||
(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]} @(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
|
||||
:submit-event submit-event
|
||||
:error error
|
||||
:status @(re-frame/subscribe [::status/single id])
|
||||
:status status
|
||||
:id id
|
||||
:data data
|
||||
:fullwidth? fullwidth?}}
|
||||
(r/as-element
|
||||
(into [:form {:on-submit (fn [e]
|
||||
(when (.-stopPropagation e)
|
||||
(.stopPropagation e)
|
||||
(.preventDefault e))
|
||||
(when can-submit
|
||||
(re-frame/dispatch-sync (vec (conj submit-event {})))))}]
|
||||
(r/children (r/current-component)))))))
|
||||
[:form {:on-submit (fn [e]
|
||||
(when (.-stopPropagation e)
|
||||
(.stopPropagation e)
|
||||
(.preventDefault e))
|
||||
(when can-submit
|
||||
(re-frame/dispatch-sync (vec (conj submit-event {})))))}
|
||||
(into [:fieldset {:disabled (boolean (= :loading (:state status)))}]
|
||||
(r/children (r/current-component)))]
|
||||
))))
|
||||
|
||||
(defn raw-field []
|
||||
(let [[child] (r/children (r/current-component))]
|
||||
@@ -55,6 +58,7 @@
|
||||
|
||||
:else
|
||||
nil)))
|
||||
|
||||
(assoc-in [1 :subscription] (aget consume-form "data"))
|
||||
(assoc-in [1 :event] (aget consume-form "change-event")))]))]))]))
|
||||
|
||||
@@ -62,6 +66,16 @@
|
||||
(r/create-element FormScopeProvider #js {:value scope}
|
||||
(r/as-element (into [:<>]
|
||||
(r/children (r/current-component))))))
|
||||
(defn vertical-control [{:keys [is-small?]}]
|
||||
(let [[label & children] (r/children (r/current-component))]
|
||||
[:> Consumer {}
|
||||
(fn [consume]
|
||||
(r/as-element
|
||||
[:div.field
|
||||
(when label (if (or (aget consume "fullwidth?")
|
||||
is-small?) [:p.help label]
|
||||
[:label.label label]))
|
||||
(into [:div.control ] children)]))]))
|
||||
|
||||
(defn field []
|
||||
(let [[label child] (r/children (r/current-component))]
|
||||
@@ -111,6 +125,16 @@
|
||||
fullwidth? (conj "is-fullwidth")) }
|
||||
child])))]))
|
||||
|
||||
(defn hidden-submit-button []
|
||||
[:> Consumer {}
|
||||
(fn [consume]
|
||||
(let [status (aget consume "status")
|
||||
can-submit (aget consume "can-submit")]
|
||||
(r/as-element
|
||||
[:div {:style {:display "none"}}
|
||||
[:button.button.is-medium.is-primary {:disabled (or (status/disabled-for status)
|
||||
(not can-submit))}]])))])
|
||||
|
||||
(defn error-notification []
|
||||
(let [[child] (r/children (r/current-component))]
|
||||
[:> Consumer {}
|
||||
|
||||
Reference in New Issue
Block a user