Set focusOut action in an {{input}} in handlebars?


#1

Is there a way to set focusOut in {{input}}. I just want a way to handle focusOut and it seems unnecessary that i have to create a view and extend from ember to do that. Is there any way around this?

Use case: Field validation


#2

There is always a way to use jquery directly but if you want to do it The Ember way, you should create the view and use the focusOut hook.


#3

Ok, but problem is. Extending from TextField, doesn’t bubble up events to the controller with focusOut. But extending from just a view works but requires duplicating TextFeildView into my own custom view. Any ideas on how to solve that?


#4

Em.TextField and Em.TextArea are moved as components with this commit . Components are isolated from the context controller. However you will be able to use sendAction method to trigger an event in the context controller.

Demo Fiddle: http://jsfiddle.net/selvaG/xJZ6Y/5/

Hope this helps you out


#5

Thanks a lot. Works smoothly :thumbsup:

Actions was missing though, so i added it incase anyone stumbles on this post http://jsfiddle.net/xJZ6Y/6/


#6

There is a simple way to do this:

 {{input type="text" value=text focus-out="focusOutInput"}}

and in your controller:

...
actions: {
    focusOutInput: function() {
        ...
    }
}

See: http://stackoverflow.com/questions/20515658/ember-input-blur-action


#7

What if the function takes an input?


#8

This works perfectly!