Created
April 25, 2016 18:31
-
-
Save rwillig/b9d8fceeef6442df2f43cd73aee3726a 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 typeahead [{:keys [options datasets id cell] :as attr :or {id (gensym)}} _] | |
(let [id (if (cell? id) @id id) | |
attrs (dissoc attr :options :datasets :cell :id) | |
field (input :id id :type "text" :change #(when (cell? cell) (reset! cell @%)) attrs) | |
select-fn (fn [cell ev s] (when (cell? cell) (reset! cell (aget s "value"))))] | |
(with-let [t (div (field))] | |
(when-dom t #(do | |
(.typeahead | |
(js/jQuery (str "#" id)) | |
(clj->js options) | |
(apply clj->js datasets)) | |
(.bind | |
(js/jQuery (str "#" id)) | |
(clj->js :typeahead:select) | |
(partial select-fn cell))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment