Ember.TextFieldBinding value with keyUp override

Why doesn't the TextField value change when overriding the keyUp function? An example is here http://jsfiddle.net/z5SNW/3/ . Basically I am alerting the TextField value when a click is entered or the user clicks on a button. The problem is that the button doesn't show the actual value until you focus from the textbox and then click the button.

I can hack it by putting an else in the keyUp function and setting a value there, but that doesn't seem right to me. I think I was just missing something very simple.


source to share

1 answer

When overridden keyUp

, the TextField value is set only when the event is change

fired (when focus is lost), see code .

If you use the available insertNewline

input for your handling, everything works: http://jsfiddle.net/z5SNW/6/ .

App = Ember.Application.create({});

App.TextField = Em.TextField.extend({
    valueBinding: 'App.TextValue.value',
    insertNewline: function() {
        alert('Submitted: ' + App.TextValue.get('value'));

App.TextValue = Em.Object.create({
    value: ''

App.SubmitButton = Em.Button.extend({
    click: function() {


Or you keep your implementation keyUp

(if you plan to act on other key code as well, but then you need to call this.interpretKeyEvents(event);

, see http://jsfiddle.net/z5SNW/8/ .



All Articles