Sets up multi date

This commit is contained in:
2024-10-22 23:55:02 -07:00
parent 77571e3589
commit 3da8bf054f
5 changed files with 74 additions and 68 deletions

View File

@@ -1,10 +1,12 @@
(ns auto-ap.ssr.components.inputs
(:require [auto-ap.ssr.components.tags :as tags]
[auto-ap.ssr.hiccup-helper :as hh]
[auto-ap.ssr.hx :as hx :refer [js-fn]]
[auto-ap.ssr.svg :as svg]
[clojure.string :as str]
[hiccup2.core :as hiccup]))
(:require
[auto-ap.ssr.components.tags :as tags]
[auto-ap.ssr.hiccup-helper :as hh]
[auto-ap.ssr.hx :as hx :refer [js-fn]]
[auto-ap.ssr.svg :as svg]
[auto-ap.time :as atime]
[clojure.string :as str]
[hiccup2.core :as hiccup]))
(def default-input-classes
@@ -349,6 +351,28 @@
(update :class #(str % (use-size size) " w-full"))
(dissoc :size))]])
(defn multi-date-input- [{:keys [size] :as params}]
(let [value (str/join ", "
(for [v (:value params)
:when v]
(some-> v (atime/unparse-local atime/normal-date))))]
(println "MY VALUE IS" value)
[:div.shrink {:x-data (hx/json {:value value})}
[:input
(-> params
(update :class (fnil hh/add-class "") default-input-classes)
(assoc :x-modelable "value")
(assoc :type "text")
(assoc :x-data (hx/json {:dp nil}) )
(assoc :value value)
(assoc :x-init " dp = initMultiDatepicker($el);")
(assoc "@htmx:before-history-save" "destroyDatepicker(dp)" )
(assoc "@htmx:before-cleanup-element" "destroyDatepicker(dp)" )
(assoc "@change" "value = $event.target.value;")
(assoc "hx-on" (hiccup/raw "changeDate: htmx.trigger(this, \"change\") "))
(update :class #(str % (use-size size) " w-full"))
(dissoc :size))]]))
(defn field-errors- [{:keys [source key]} & rest]