This commit is contained in:
leo 2021-11-05 14:25:35 +01:00
parent 86b6e890cf
commit bb7757338c

View file

@ -18,10 +18,11 @@
(s/def ::deserializer fn?) (s/def ::deserializer fn?)
(s/def ::optional boolean?) (s/def ::optional boolean?)
(def dom-function-parameter (s/keys :opt-un [::deserializer ::optional]))
(defn-spec get-content-from-element any? (defn-spec get-content-from-element any?
[name string? [name string?
& {:keys [deserializer optional] & {:keys [deserializer optional]
:or {deserializer nil optional false}} (s/keys :opt-un [::deserializer ::optional])] :or {deserializer nil optional false}} dom-function-parameter]
(let [content (-> (get-element-by-id name) (let [content (-> (get-element-by-id name)
(.-value))] (.-value))]
(cond (cond
@ -47,7 +48,7 @@
[name string? [name string?
spec any? spec any?
& {:keys [deserializer optional] & {:keys [deserializer optional]
:or {deserializer nil optional false}} (s/keys :opt-un [::deserializer ::optional])] :or {deserializer nil optional false}} dom-function-parameter]
(let [content (get-content-from-element name :optional optional :deserializer deserializer)] (let [content (get-content-from-element name :optional optional :deserializer deserializer)]
(if (or (and optional (st/blank? content)) (if (or (and optional (st/blank? content))
(s/valid? spec content)) (s/valid? spec content))
@ -55,14 +56,15 @@
(set-validation-result! name (set-validation-result! name
(expound/expound-str spec content {:print-specs? false}))))) (expound/expound-str spec content {:print-specs? false})))))
(defn set-output! (defn-spec set-output! any?
[input] [input string?]
(-> js/document (-> js/document
(.getElementById "output") (.getElementById "output")
(.-value) (.-value)
(set! input))) (set! input)))
(defn set-validated! [] (defn-spec set-validated! any?
[]
(-> (get-element-by-id "form") (-> (get-element-by-id "form")
(.-classList) (.-classList)
(.add "was-validated"))) (.add "was-validated")))