Skip to content

Commit

Permalink
Adds client side form validations to create activity form
Browse files Browse the repository at this point in the history
  • Loading branch information
MTrost committed Aug 4, 2024
1 parent 2463870 commit 0b80d4b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/co/gaiwan/compass/html/navigation.clj
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
[:li [:a {:href "/"} "Sessions & Activities"]]
[:li [a-auth {:href "/attendees"} "Attendees"]]
[:li [a-auth {:href "/profile"} "Profile & Settings"]]
[:li [a-auth {:href "/sessions/new"} "Create Activity"]]]]))
[:li [a-auth {:href "/sessions/new"
:user user} "Create Activity"]]]]))

(o/defrules toggle-menu-button)

Expand Down
22 changes: 14 additions & 8 deletions src/co/gaiwan/compass/html/sessions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -219,33 +219,37 @@

(o/defstyled session-form :div
[:form :grid {:grid-template-columns "10rem 1fr"} :gap-2]
[:div.date-time {:display "flex" :gap "0.5rem"}]
([params]
[:<>
[:h2 "Create Activity"]
[:form {:method "POST" :action "/sessions"}
[:label {:for "title"} "Title"]
[:input {:id "title" :name "title" :type "text"}]
[:input {:id "title" :name "title" :type "text"
:required true :min-length 2}]

[:label {:for "subtitle"} "Subtitle"]
[:input {:id "subtitle" :name "subtitle" :type "text"}]
[:input {:id "subtitle" :name "subtitle" :type "text"
:min-length 10}]

[:label {:for "start-time"} "Start Time"]
[:div
[:div.date-time
[:select {:id "start-date" :name "start-date"}
(let [day-before 3
day-after 3]
(for [day (range (- 4 day-before) (+ 4 day-after))]
[:option {:value (format "2024-08-%02d" day)} (format "2024-08-%02d" day)]))]
[:input {:id "start-time" :name "start-time" :type "time"
:min "08:00" :max "19:00"}]]
:min "06:00" :max "23:00" :required true
:step (* 5 60)}]]

[:label {:for "duration-time"} "Duration Time"]
[:input.html-duration-picker
{:id "duration-time" :name "duration-time" :data-hide-seconds true}]

[:label {:for "type"} "Type"]
[:select {:id "type" :name "type"}
[:option {:value "activity"} "activity"]]
[:select {:id "type" :name "type"}
[:option {:value "activity"} "Activity"]]

[:label {:for "location"} "Location"]
[:select {:id "location" :name "location"}
Expand All @@ -260,10 +264,12 @@
[:option {:value "hal5-long-table"} "Hal 5 - long table"]]

[:label {:for "capacity"} "Capacity"]
[:input {:id "capacity" :name "capacity" :type "number" :value 0}]
[:input {:id "capacity" :name "capacity" :type "number"
:min 2 :value 2 :required true }]

[:label {:for "description"} "Description"]
[:textarea {:id "description" :name "description"}]
[:textarea {:id "description" :name "description"
:required true}]

[:label {:for "ticket"} "Requires Ticket?"]
[:input {:id "ticket" :name "ticket-required?" :type "checkbox"}]
Expand Down
3 changes: 2 additions & 1 deletion src/co/gaiwan/compass/routes/sessions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
[{:keys [title subtitle start-date start-time duration-time description
type location
capacity
ticket-required? published?]}]
ticket-required? published?]
:or {type "activity"}}]
(let [local-date (time/local-date start-date)
local-time (time/local-time start-time)
local-date-time (time/local-date-time local-date local-time)
Expand Down

0 comments on commit 0b80d4b

Please sign in to comment.