Skip to content

Instantly share code, notes, and snippets.

@joelkuiper
Last active December 11, 2015 16:34
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 joelkuiper/0b970745cda78de007a0 to your computer and use it in GitHub Desktop.
Save joelkuiper/0b970745cda78de007a0 to your computer and use it in GitHub Desktop.
(defn selectize
[options settings]
(let [id
(util/rand-uuid)
get-selectize
(fn [] (.-selectize (aget (js/$ (str "#" id)) 0)))
selectize!
(fn [this]
(let [[_ options _ _ ] (reagent/argv this)]
(.selectize
(js/$ (str "#" id))
(clj->js (assoc settings :options (vec (:options options)))))
(.setValue (get-selectize) (clj->js (:defaults options)))))]
(reagent/create-class
{:component-did-mount selectize!
:component-will-unmount #(.destroy (get-selectize))
:render (fn [] [:input {:id id}])})))
[selectize
{:defaults []
:options []} ;; options and default selected
{:plugins ["remove_button"] ;; all other selectize settings
:onChange update!}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment