Add a validation for the edit article form.

This commit is contained in:
2024-04-19 09:41:31 +03:00
parent 4e6d36d98c
commit 88a9eb7749
3 changed files with 70 additions and 5 deletions
+49 -1
View File
@@ -211,6 +211,54 @@
(res/status 500)
(res/send (ex-message err))))))))
(defn htmx-update-title-validation-handler-factory
[]
(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 "update_title_validation"
(-> {:error error
:title title
:layout false}
(clj->js))))
(catch js/Error err
(res/status 500)
(res/send (ex-message err))))))))
(defn htmx-update-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 "update_content_validation"
(-> {:error error
:content content
:layout false}
(clj->js))))
(catch js/Error err
(res/status 500)
(res/send (ex-message err))))))))
(defn htmx-update-article-handler-factory
[client]
(fn [req res]
@@ -313,7 +361,7 @@
(res/send (ex-message err))))))))
(defn htmx-create-title-validation-handler-factory
[client]
[]
(fn [req res]
(let [channel (chan)
title (.-title (.-body req))
+14
View File
@@ -149,6 +149,20 @@
(. app use "/htmx/admin/rows/article/:id/"
(handlers/user-not-authorized-factory))
(. app post "/htmx/validation/update-title/"
handlers/is-user-authorized
(handlers/htmx-update-title-validation-handler-factory))
(. app use "/htmx/validation/update-title/"
(handlers/user-not-authorized-factory))
(. app post "/htmx/validation/update-content/"
handlers/is-user-authorized
(handlers/htmx-update-content-validation-handler-factory))
(. app use "/htmx/validation/update-content/"
(handlers/user-not-authorized-factory))
(. app patch "/htmx/admin/rows/article/:id/"
handlers/is-user-authorized
(handlers/htmx-update-article-handler-factory client))