reagent-project / reagent-forms

Bootstrap form components for Reagent
339 stars 78 forks source link

Typeahead - Index out of bounds when pressing enter with element not matching #73

Closed tech-Nico closed 8 years ago

tech-Nico commented 9 years ago

When typing in a typeahead, if I type a string for which the function associated to data-source returns nil and then I press enter, a JS exception is thrown:

Uncaught Error: Index out of bounds

The exception is caused by

choose-selected #(do (let [choice (nth @selections @selected-index)]
                               (save! id choice)
                               (choice-fn choice))
                             (reset! typeahead-hidden? true))

and specifically by

(nth @selections @selected-index)

Unfortunately I'm not good enough to be able and identify the cause of the issue, but I could replicate it on the reagent-forms demo application.

yogthos commented 9 years ago

This sounds similar to this issue, are you sure you're on the latest version?

tech-Nico commented 9 years ago

Apologise.. I should have searched for closed issues. Anyway, I seem to be on the latest version. These are the dependencies in my project.clj

:dependencies [[org.clojure/clojure "1.7.0"]
                 [ring-server "0.4.0"]
                 [cljsjs/react "0.13.3-1"]
                 [reagent "0.5.1"]
                 [reagent-forms "0.5.9"]
                 [reagent-utils "0.1.5"]
                 [ring "1.4.0"]
                 [ring/ring-defaults "0.1.5"]
                 [prone "0.8.2"]
                 [compojure "1.4.0"]
                 [hiccup "1.0.5"]
                 [environ "1.0.0"]
                 [org.clojure/clojurescript "1.7.122" :scope "provided"]
                 [secretary "1.2.3"]]

I'm possibly doing something else wrong.. I'll check everything is in place.

yogthos commented 9 years ago

That looks fine, only other thing I can think of is to clean out the generated js files. If it's still not working then there's a bug. :)

yogthos commented 9 years ago

I did notice there's a poor behavior for handling the situation when the element was selected from the list previously it would overwrite the input even when it doesn't match. I pushed out a fix for that with 0.5.11. Let me know if that might help.