Reputation: 44757
I'm trying out Ember.js but I'm stuck when using actions.
If I use the following:
<button {{action "test"}}>Test</button>
And create a controller:
App.NewController = Ember.ArrayController.extend({
actions: {
test: function() {
console.log("test");
},
}
});
Then everything works fine and I can see test
in my log. However, when I try the following:
<input type="text" {{action "test2" on="keyUp"}} />
And define the test2
action in a similar way:
App.NewController = Ember.ArrayController.extend({
actions: {
test: function() {
console.log("test");
},
test2: function() {
console.log("test2");
}
}
});
Then it doesn't seem to work. My test button is working, but the keyup event handler is not fired as I expected after reading the documentation.
Upvotes: 2
Views: 3726
Reputation: 8389
It looks like there is a bug (or at least very odd behavior) affecting the ability to use actions with keyboard events. Normally, actions handlers for non-keyboard events (like the default "click" event) don't work when modifier keys are pressed. In your code, if you add allowedKeys="any"
to your action helper, then your handler will get invoked.
Fiddle: http://emberjs.jsbin.com/oyEpImI/2/edit?html,js,output
Upvotes: 1
Reputation: 47367
That's really weird, I'll keep looking into it, but you could just use the input helper and observe the value, additionally you could extend the textfield and get the keyup there if you care about which key they are pressing.
http://emberjs.jsbin.com/EBoLEZe/1/edit
{{input value=name}}
postKey: function(){
console.log(this.get('name'));
}.observes('name')
See also: KeyPress event not working as expected in Ember
Upvotes: 3