This commit is contained in:
jem 2021-03-19 15:23:12 +01:00
parent 1866134d1e
commit 87c0c53df1
2 changed files with 19 additions and 17 deletions

View file

@ -12,7 +12,9 @@
#?(:clj (alter-var-root #'s/*explain-out* (constantly expound/printer)) #?(:clj (alter-var-root #'s/*explain-out* (constantly expound/printer))
:cljs (set! s/*explain-out* expound/printer)) :cljs (set! s/*explain-out* expound/printer))
(s/def ::config cd/config?) (def config? cd/config?)
(def auth? (s/keys :req-un [::cd/auth]))
(defn generate-config [my-config my-auth] (defn generate-config [my-config my-auth]
(-> (->

View file

@ -17,13 +17,6 @@
(-> js/document (-> js/document
(.getElementById "auth"))) (.getElementById "auth")))
(defn set-config-validation! [input]
(print-debug input)
(-> js/document
(.getElementById "config-validation")
(.-innerHTML)
(set! input)))
(defn form [] (defn form []
(-> js/document (-> js/document
(.getElementById "form"))) (.getElementById "form")))
@ -45,22 +38,21 @@
(defn set-config-validation-result! (defn set-config-validation-result!
[validation-result] [validation-result]
(print-debug validation-result) (-> js/document
(set-config-validation! validation-result) (.getElementById "config-validation")
(.-innerHTML)
(set! validation-result))
(-> (config) (-> (config)
(.setCustomValidity validation-result)) (.setCustomValidity validation-result))
(-> (form)
(.-classList)
(.add "was-validated"))
validation-result) validation-result)
(defn validate-config! [] (defn validate-config! []
(let [config-str (config-from-document) (let [config-str (config-from-document)
config-map (edn/read-string config-str)] config-map (edn/read-string config-str)]
(if (s/valid? ::core/config config-map) (if (s/valid? core/config? config-map)
(set-config-validation-result! "") (set-config-validation-result! "")
(set-config-validation-result! (set-config-validation-result!
(expound/expound-str ::core/config config-map {:print-specs? false}))))) (expound/expound-str core/config? config-map {:print-specs? false})))))
(defn set-validated! [] (defn set-validated! []
(-> (form) (-> (form)
@ -80,9 +72,11 @@
(defn validate-auth! [] (defn validate-auth! []
(let [auth-str (auth-from-document) (let [auth-str (auth-from-document)
auth-map (edn/read-string auth-str)] auth-map (edn/read-string auth-str)]
(when-not (s/valid? ::core/auth auth-map) (print-debug (s/valid? core/auth? auth-map))
(if (s/valid? core/auth? auth-map)
(set-auth-validation-result! "")
(set-auth-validation-result! (set-auth-validation-result!
(expound/expound-str ::core/auth auth-map {:print-specs? false}))))) (expound/expound-str core/auth? auth-map {:print-specs? false})))))
(defn init [] (defn init []
(-> js/document (-> js/document
@ -93,4 +87,10 @@
(-> (config) (-> (config)
(.addEventListener "blur" (.addEventListener "blur"
#(do (validate-config!) #(do (validate-config!)
(validate-auth!)
(set-validated!))))
(-> (auth)
(.addEventListener "blur"
#(do (validate-config!)
(validate-auth!)
(set-validated!))))) (set-validated!)))))