Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polymer input capture enter event

I'm trying to detect when a user presses return/enter in a chat box to send the message. How do I detect this for a paper-input element?

like image 456
Christian Stewart Avatar asked Jul 20 '26 14:07

Christian Stewart


1 Answers

paper-input inherits from core-input, which fires a change event when the users hits enter/return or the element loses focus. If you don't care about the losing focus case (e.g only want the case where the user hits ENTER), you could check the document.activeElement:

document.querySelector('paper-input').addEventListener('change', function(e) {
  if (document.activeElement == this) {
    console.log('ENTER hit on aper-input');
  }
});

http://jsbin.com/godaqugacecu/1/edit

See http://www.polymer-project.org/docs/elements/core-elements.html#core-input.

like image 138
ebidel Avatar answered Jul 25 '26 04:07

ebidel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!