I need to submit changes when the Enter key is pressed, rather than typing a newline symbol. I'm using Ember.js and slightly customized TextArea helper.
Here is what I have in my template
{{edit-item placeholder="Weight" value=weight insert-newline="acceptChanges" focus-out="acceptChanges"}}
in my helper
App.EditItemView = Em.TextArea.extend
didInsertElement: ->
this.$().focus()
this.$().blur()
focusIn: ->
$this = this.$()
$this.get(0).select()
# fix webkit select problems
mouseUpHandler = ->
$this.off("mouseup", mouseUpHandler)
return false
$this.mouseup(mouseUpHandler)
attributeBindings: ['style', 'placeholder']
Em.Handlebars.helper 'edit-item', App.EditItemView
and in my acceptChagnges action
# In controller action hook up
acceptChanges: ->
$(document.activeElement).blur()
@get('model').save()
The real problem is that when text selected and user types enter key to accept, it also types a newline which replaces all content in textarea, hence the only newline gets accepted.
How to prevent typing new line, but fire an event to accept changes?