This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-11-20
Channels
- # admin-announcements (28)
- # aws (16)
- # beginners (70)
- # boot (54)
- # cider (86)
- # cljsrn (8)
- # clojure (14)
- # clojure-art (12)
- # clojure-conj (2)
- # clojure-hk (45)
- # clojure-nl (2)
- # clojure-poland (2)
- # clojure-russia (32)
- # clojurescript (60)
- # cursive (27)
- # datomic (12)
- # devcards (46)
- # editors (2)
- # emacs (37)
- # immutant (72)
- # jobs (6)
- # ldnclj (7)
- # leiningen (1)
- # off-topic (1)
- # om (205)
- # onyx (16)
- # re-frame (21)
- # reagent (52)
- # slack-help (2)
- # spacemacs (11)
I've got a re-com question. Let's say I've got an input-text and a button, how do I make hitting enter when the input-text is active trigger the button's on-click? Looking through the recom demo for modal popup has a similar example: https://github.com/Day8/re-com/blob/bf0107cedab51fa5a1789c4035aeebb9ba2edd8e/src/re_demo/modal_panel.cljs#L88, but it appears to just only trigger the first button child.
In plain reagent I'd use:
[:form {:on-submit (fn [e] (.preventDefault e))}
[input-box-thing]
[:button.cancel ,,,] ;;<-- don't click this on enter from input-box-thing
[:button.submitme {:type "submit",,,}]]
Could you make the on-blur for the input to the same dispatch
as the button's click
handler?
Code like this has worked for me:
[re-com/input-text
:model some-text
:on-change #(reset! some-text %)
:attr {:auto-focus true
:on-focus (handler-fn (-> event .-target .select))
:on-key-press (handler-fn (case (.-which event)
13 (submit-form)
nil))}]
submit-form
would be the same code/dispatch that is called when the button is clicked.
I have also included the code to initially select the text (`:auto-focus`) and to then select the text when it receives the focus (`:on-focus`) in case you're interested.You could also add a 27
in the case
function to handle the Esc key being pressed and run your cancel code/dispatch
it is a pleasure to work with re-com
guys, thanks, and the last figwheel does not even fully reload the page!
Thanks @richiardiandrea. Do you want to expand on your figwheel comment?
Before it was reloading the whole page at every change
version 0.4.1, now with version 0.5.0 it just reloads the changed components, or in any case, it is way ffaster, dunno what exactly Bruce has done 😄
or you guys, I also switched to alpha2
my web app
Here is the code, it should explain it better: https://github.com/Day8/re-com/blob/master/src/re_com/core.clj#L43