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

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

1 Like

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.

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?

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: Edit fiddle - JSFiddle - Code Playground

Hope this helps you out

1 Like

Thanks a lot. Works smoothly :thumbsup:

Actions was missing though, so i added it incase anyone stumbles on this post Edit fiddle - JSFiddle - Code Playground

There is a simple way to do this:

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

and in your controller:

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

See: javascript - Ember input blur action - Stack Overflow

1 Like

What if the function takes an input?

2 Likes

This works perfectly!