How to trigger an action when input gets focus?

I want to know how to initiate an action when input becomes targeted.
right now I am using this on my template: {{view "clickinput" class="form-control" placeholder="search..." value=s action="focus"}}
and it is like a view:

 export default Ember.TextField.extend({ onEvent: 'focusIn', focusIn: function() { this.sendAction('focusIn', this, event); } }); 

and this is on my controller:

 actions: { focus: function() { alert('f'); } } 

but it does not work.
I get this error on chrome: Uncaught Error: Assertion Failed: The focusIn action was triggered on the component < appkit@view :clickinput::ember438>, but the action name (function superWrapper() { var ret, sup = this.__nextSuper; this.__nextSuper = superFunc; ret = func.apply(this, arguments); this.__nextSuper = sup; return ret; }) was not a string.

why?

+7
source share
2 answers

It turned out to be easier than I thought ..
I just had to write {{input class="form-control" placeholder="search..." value=s focus-in="focus"}} in my template

+15
source share

I used your answer as a starting point, so thanks! Here is what worked for me:

Amber statistics:

 DEBUG: ------------------------------- DEBUG: Ember : 1.7.1 DEBUG: Ember Data : 1.0.0-beta.11 DEBUG: Handlebars : 1.3.0 DEBUG: jQuery : 2.1.3 DEBUG: Model Fragments : 0.2.7 DEBUG: ------------------------------- 

My common functions, I call .js functions

 Ember.TextField.reopen({ attributeBindings: ['data-stripe'], focusIn: function() { return this.sendAction('focus-in'); } }); 

My controller

  actions: { focusField: function() { debugger; } } 

My Handlebars Template

 {{input focus-in="focusField" type="tel" maxlength="20" data-stripe="number" placeholder="Card Number" value=input.number autocomplete="cc-number"}} 
-one
source share

All Articles