Skip to content

Instantly share code, notes, and snippets.

@lsgrep
Last active July 19, 2022 21:28
Show Gist options
  • Save lsgrep/0eea03fc50121dac0709 to your computer and use it in GitHub Desktop.
Save lsgrep/0eea03fc50121dac0709 to your computer and use it in GitHub Desktop.
reagent input with Chinese characters
;reagent input two way binding with chinese characters .
;reagent 中文输入问题
@lsgrep
Copy link
Author

lsgrep commented Mar 19, 2016


(defn cjk-input [opts]
  (let [regex-compo-on? (atom false)
        on-change-fn (:on-change-fn opts)]
    [:input (merge  {:type "text"
                     :on-composition-start (fn [e]
                                             (reset! regex-compo-on? true))
                     :on-composition-end (fn [e]
                                           (reset! regex-compo-on? false))

                     :on-change (fn [e]                                        
                                  (let [val (-> e .-target .-value)]
                                    (when-not @regex-compo-on?
                                      (on-change-fn val))))}

                    (dissoc opts :on-change-fn))]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment