These are chat archives for opal/opal

29th
Nov 2017
Ruben De Andrade
@RubenDeAndrade
Nov 29 2017 13:53
Hello Guys !! I wonder how i can detect a Enter key press with Opal rails. If someone can help me ! Thank you :smile:
Ruben De Andrade
@RubenDeAndrade
Nov 29 2017 14:01
Nevermind, I find the answer :smile: The answer is: Element.on :keypress { |event| event.which == 13 (13 is Enter keyCode) }
rangeoshun
@rangeoshun
Nov 29 2017 16:46

Hello there! I just face an issue, or actually two. I hope you guys can help. So:

Issue 1.
When I use .addEventListener(:keydown) { |event| handle_name_change(event) }, the event is not wrapped in, and I get this error:

Uncaught TypeError: event.$target is not a function

Can I get opal to wrap the event, or am I doing things the wrong way?

Issue 2.

All JS is executed 3 times for some reason, and I do not know why. Can you help, or guess?

Here's the repo: https://github.com/rangeoshun/wromoror

The files in hand is /app/assets/javascripts/setup.js.rb

Updated my question, thanks, and cheers!
rangeoshun
@rangeoshun
Nov 29 2017 17:00
Adding: in the handle_name_change method I try to read the event.target.value.
rangeoshun
@rangeoshun
Nov 29 2017 17:32
Issue 2 might be a turbolinks problem I think.
rangeoshun
@rangeoshun
Nov 29 2017 21:09
Ok, I switched to the Element.find("selector").on { |ev| ... }
But still find strange, that the native way does not work as one would expect.