This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-09
Channels
- # beginners (38)
- # boot (160)
- # cider (143)
- # cljs-dev (62)
- # cljsjs (2)
- # cljsrn (3)
- # clojure (278)
- # clojure-austin (8)
- # clojure-brasil (5)
- # clojure-greece (2)
- # clojure-italy (11)
- # clojure-russia (188)
- # clojure-sg (2)
- # clojure-spec (118)
- # clojure-uk (103)
- # clojurescript (87)
- # core-async (8)
- # cryogen (2)
- # cursive (12)
- # datomic (119)
- # emacs (13)
- # hoplon (4)
- # immutant (12)
- # off-topic (12)
- # om (54)
- # om-next (5)
- # onyx (1)
- # pedestal (2)
- # portland-or (2)
- # re-frame (58)
- # reagent (18)
- # ring-swagger (18)
- # rum (4)
- # spacemacs (4)
- # specter (3)
- # untangled (65)
- # yada (25)
How would you costruct a text field where pressing the enter key clears the field and sends the value of the field somewhere?
@rovanion I guess I would do that in the :on-submit
handler of the surrounding form ?
@val_waeselynck Hmm, I used the wrong term. I meant textarea and not textfield.
Right now I got this:[:textarea {:id "send" :disabled false :on-change #(reset! atom (-> % .-target .-value)) :on-key-press (fn [e] (when (= 13 (.-charCode e)) (send-chat!)))}]
and surrounding this with a form does not work ?
@val_waeselynck Well pressing enter in a textarea just enters \n, it doesn't perform a submit action.
hum yeah you're right of course
well then is the textarea really what you want?
Well imagine that I bound send to ctrl-enter instead. The problem is the same: There are two event handlers that get into a race condition.
(let [a (atom "")] [:textarea {:id "send" :on-change #(reset! atom (-> % .-target .-value)) :on-key-press (fn [e] (when (= 13 (.-charCode e)) (send-chat!) (reset! a "")))}])
Right now :on-change happens after :on-key-press but with the old value of the field and resets the field to contain the text that was just removed in :on-key-press.
for the record, the Slack chat into which I'm typing uses on-submit 🙂
Something tells me that the 2 events have to happen in the same JS loop iteration
so maybe you could use a debounce or something like that
I can't get the :on-submit event to fire when I press enter I'm afraid. Still, it seems logical that it would suffer the same type of issue, I still have two events.
I've had similar issues in the past and concluded that listening for charCode 13 works best