improved two major forms.

This commit is contained in:
2022-07-19 15:10:33 -07:00
parent 483e9ad311
commit 0baab4eaf0
14 changed files with 431 additions and 355 deletions

View File

@@ -7,7 +7,8 @@
[auto-ap.forms :as forms]
[auto-ap.status :as status]
[malli.core :as m]
[malli.error :as me]))
[malli.error :as me]
[clojure.string :as str]))
(defonce ^js/React.Context form-context (react/createContext "default"))
(def ^js/React.Provider Provider (. form-context -Provider))
@@ -161,7 +162,9 @@
[:div
[:p.help.has-text-danger error-message]]))))]))])
(defn raw-field-v2 [{:keys [field]}]
(defn raw-field-v2 [{:keys [field] :as props}]
(when-not field
(throw (ex-info (str "Missing field") (clj->js {:props props}))))
(let [[child] (r/children (r/current-component))]
[:> Consumer {}
(fn [consume-form]
@@ -188,7 +191,6 @@
(if on-change
(partial form-change-handler (aget consume-form "data") full-field-path (aget consume-form "on-change"))
(partial change-handler full-field-path (aget consume-form "change-event")))
:on-blur (partial blur-handler full-field-path (aget consume-form "blur-event"))
:value value)
(update :class (fn [class]
@@ -198,8 +200,12 @@
""
(not (valid-field? (aget consume-form "problems") full-field-path))
" is-danger"
value
"is-success"
:else
"is-success"))))))))))]))]))
""))))))))))]))]))
(defn with-scope [{:keys [scope]}]
(r/create-element FormScopeProvider #js {:value scope}