reagent-project / reagent-forms

Bootstrap form components for Reagent
339 stars 78 forks source link

Datepicker errors on version 0.5.17 #89

Closed jaaqo closed 8 years ago

jaaqo commented 8 years ago

Steps to reproduce:

  1. lein new reagent datepicker-test
  2. Change reagent-forms to 0.5.17 in project.clj
  3. Add reagent-forms to namespace of core.cljs and include forms css in loading-page
  4. Add a simple form

    (def form-template
     [:div
      {:field :datepicker :id :age :date-format "yyyy/mm/dd" :inline true}])
    
    (defn home-page []
     (let [doc (atom {})]
       (fn []
         [:div [:h2 "Datepicker"]
          [:div [bind-fields form-template doc]]])))
  5. lein figwheel

Results in

1

And latter expanded:

2

After little debugging it seems the month in :init-field datepicker is -1 which later causes the error.

Somehow line 140 in reagent-forms.core results in -1.. Is there something I'm doing wrong?

(defmethod init-field :datepicker
  [[_ {:keys [id date-format inline auto-close?] :as attrs}] {:keys [doc get save!]}]
  (let [fmt (parse-format date-format)
        selected-date (get id)
        today (js/Date.)
        year (or (:year selected-date) (.getFullYear today))
        month (or (dec (:month selected-date)) (.getMonth today))    <---  equals -1
        day (or (:day selected-date) (.getDate today))
        expanded? (atom false)]
jaaqo commented 8 years ago

This error does not happen on commit 8f513c16c451c69b6a244d95830b18d8c93edf11

yogthos commented 8 years ago

Yeah, it looks like a bug snuck in with the latest pr. Looks like it would just need to check that the month is not 0 on the selected-date before decrementing.

yogthos commented 8 years ago

just pushed your fix to clojars, let me know if everything looks good

jaaqo commented 8 years ago

Works fine now!

yogthos commented 8 years ago

:+1: