Add a validation for the create form.
This commit is contained in:
@@ -312,6 +312,54 @@
|
||||
(res/status 500)
|
||||
(res/send (ex-message err))))))))
|
||||
|
||||
(defn htmx-create-title-validation-handler-factory
|
||||
[client]
|
||||
(fn [req res]
|
||||
(let [channel (chan)
|
||||
title (.-title (.-body req))
|
||||
content (.-content (.-body req))]
|
||||
(go
|
||||
(try
|
||||
(let [error (cond
|
||||
(= (count title) 0)
|
||||
"Tittle must be nonempty!!!"
|
||||
|
||||
:else
|
||||
nil)]
|
||||
(res/status 200)
|
||||
(.render res "create_title_validation"
|
||||
(-> {:error error
|
||||
:title title
|
||||
:layout false}
|
||||
(clj->js))))
|
||||
(catch js/Error err
|
||||
(res/status 500)
|
||||
(res/send (ex-message err))))))))
|
||||
|
||||
(defn htmx-create-content-validation-handler-factory
|
||||
[]
|
||||
(fn [req res]
|
||||
(let [channel (chan)
|
||||
title (.-title (.-body req))
|
||||
content (.-content (.-body req))]
|
||||
(go
|
||||
(try
|
||||
(let [error (cond
|
||||
(= (count content) 0)
|
||||
"Content must be nonempty!!!"
|
||||
|
||||
:else
|
||||
nil)]
|
||||
(res/status 200)
|
||||
(.render res "create_content_validation"
|
||||
(-> {:error error
|
||||
:content content
|
||||
:layout false}
|
||||
(clj->js))))
|
||||
(catch js/Error err
|
||||
(res/status 500)
|
||||
(res/send (ex-message err))))))))
|
||||
|
||||
(defn htmx-create-article-handler-factory
|
||||
[client]
|
||||
(fn [req res]
|
||||
|
||||
@@ -111,6 +111,20 @@
|
||||
(. app post "/htmx/search/articles/"
|
||||
(handlers/htmx-search-articles-handler-factory client))
|
||||
|
||||
(. app post "/htmx/validation/create-title/"
|
||||
handlers/is-user-authorized
|
||||
(handlers/htmx-create-title-validation-handler-factory client))
|
||||
|
||||
(. app use "/htmx/validation/create-title/"
|
||||
(handlers/user-not-authorized-factory))
|
||||
|
||||
(. app post "/htmx/validation/create-content/"
|
||||
handlers/is-user-authorized
|
||||
(handlers/htmx-create-content-validation-handler-factory))
|
||||
|
||||
(. app use "/htmx/validation/create-content/"
|
||||
(handlers/user-not-authorized-factory))
|
||||
|
||||
(. app post "/htmx/articles/"
|
||||
handlers/is-user-authorized
|
||||
(handlers/htmx-create-article-handler-factory client))
|
||||
|
||||
Reference in New Issue
Block a user