2

I have used addon ember-autoresize for my textarea to resize my textarea.

{{textarea type="text" placeholder="Comment" value=comment_text autofocus="autofocus" rows=1 max-rows=4 autoresize=true 
      enter="commentSave"}}

I want to trigger the action when user press enter.But it moves to next line when I press enter.How do I call the action when enter key is pressed in textarea.

nandanself
  • 825
  • 8
  • 17

1 Answers1

3

Create component called custom-textarea.

in components/custom-textarea.js:

export default Ember.TextArea.extend({
  didRender() {
    this.$().keypress(function(event) {
      if (event.keyCode == 13) {
        event.preventDefault();
      }
    });
  }
});

In template, use custom-textarea instead of textarea:

{{custom-textarea type="text" placeholder="Comment" value=comment_text autofocus="autofocus" rows=1 max-rows=4 autoresize=true 
      enter="commentSave"}}

See WORKING DEMO.

Approach to prevent default behavior taken from this answer.

Community
  • 1
  • 1
Daniel Kmak
  • 16,209
  • 7
  • 65
  • 83