Add a validation for the about form in the admin panel.
This commit is contained in:
@@ -258,6 +258,29 @@
|
||||
(res/status 500)
|
||||
(res/send (ex-message err))))))))
|
||||
|
||||
(defn htmx-about-validation-handler-factory
|
||||
[]
|
||||
(fn [req res]
|
||||
(let [channel (chan)
|
||||
about-content (.-content (.-body req))]
|
||||
(go
|
||||
(try
|
||||
(let [error (cond
|
||||
(= (count about-content) 0)
|
||||
"Content must nonempty!!!"
|
||||
|
||||
:else
|
||||
nil)]
|
||||
(res/status 200)
|
||||
(.render res "about_content_validation"
|
||||
(-> {:error error
|
||||
:about-content about-content
|
||||
:layout false}
|
||||
(clj->js))))
|
||||
(catch js/Error err
|
||||
(res/status 500)
|
||||
(res/send (ex-message err))))))))
|
||||
|
||||
(defn htmx-update-about-handler-factory
|
||||
[client]
|
||||
(fn [req res]
|
||||
|
||||
@@ -94,6 +94,13 @@
|
||||
(. app use "/admin"
|
||||
(handlers/user-not-authorized-factory))
|
||||
|
||||
(. app post "/htmx/validation/about/"
|
||||
handlers/is-user-authorized
|
||||
(handlers/htmx-about-validation-handler-factory))
|
||||
|
||||
(. app use "/htmx/validation/about/"
|
||||
(handlers/user-not-authorized-factory))
|
||||
|
||||
(. app patch "/htmx/about/"
|
||||
handlers/is-user-authorized
|
||||
(handlers/htmx-update-about-handler-factory client))
|
||||
|
||||
Reference in New Issue
Block a user