Created
April 21, 2016 18:28
-
-
Save rwillig/5956ddafdabd1dd29784b0eff7550842 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defelem currency-typeahead [{:keys [value options currency id cell] :as attr :or {id (gensym)}} _] | |
(cell= (.log js/console "options " (clj->js options))) | |
(let [id (if (cell? id) @id id) | |
matcher (fn [options] | |
(fn [q cb] | |
(let [os (mapv str (js->clj options))] | |
(if | |
(= q "") | |
(do (cb (clj->js os))) | |
(let [bs (filterv #(startsWith % q) os)] | |
(cb (clj->js bs)))))))] | |
(with-let [t (div | |
(currency-span :currency currency | |
(input :id id :type "text" :placeholder value :change #(do (.log js/console @%) (when (cell? cell) (reset! cell @%))))))] | |
(when-dom t #(do | |
(.log js/console "initialize typeahead") | |
(.typeahead | |
(js/jQuery (str "#" id)) | |
(clj->js {:minLength 0 :highlight true}) | |
(clj->js {:limit 100 :name "amounts" :source (matcher (clj->js @options))}))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment