Skip to content

Instantly share code, notes, and snippets.

@rwillig
Created April 21, 2016 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwillig/5956ddafdabd1dd29784b0eff7550842 to your computer and use it in GitHub Desktop.
Save rwillig/5956ddafdabd1dd29784b0eff7550842 to your computer and use it in GitHub Desktop.
(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