Terence Chow
Terence Chow

Reputation: 11173

get the value of an input on changed value in Ember

I have the following action in my controller:

actions:{
    doSomething:function(a){console.log("do something",a)}
}

In my template I have:

{{input value=50 name=variableName action="doSomething" on="input"}}

However the function never fires when I change the input value, ie by typing or deleting the placeholder value of 50.

What am I doing wrong and how do I get the changed value of the input box?

Note: I use on="input" because I want to do something when the input value changes, but let me know if I should be using a different event. Using key-press results in the method firing, but the input value printed to the console is the 'before-any-changes' input value. I need the input value after someone has typed into the field. I tried using key-up but the method doesn't fire.

Upvotes: 1

Views: 991

Answers (1)

Jakeii
Jakeii

Reputation: 1273

Use an observer on variableName it will trigger the function whenever it changes,

onInput: function() {
  // do something
}.observes('variableName')

see the guide for more details http://guides.emberjs.com/v1.11.0/object-model/observers/

Upvotes: 2

Related Questions