Sunday, 15 September 2013

javascript - set focus in an ember application -



javascript - set focus in an ember application -

i want able set focus textarea result of mouse click not in task area.

as minimal example, let's i'm starting text , if click on it, gets replaced textfield. can accomplish handlebars script:

<script type="text/x-handlebars"> {{#if isactive}} {{view ember.textfield}} {{else}} <p {{action foo}}> click here come in text </p> {{/if}} </script>

with controller of

app.applicationcontroller = ember.controller.extend({ isactive: false, foo: function(){ this.set("isactive", true); } });

this works create textfield on click, not give focus text area (it takes sec click able come in text).

is there way accomplish end? hacky setting id in template , selecting jquery, seems inelegant.

consider extending ember.textfield follows:

app.focusedtextfield = em.textfield.extend({ didinsertelement: function() { this.$().focus(); } });

then alter handlebars template utilize instead:

<script type="text/x-handlebars"> {{#if isactive}} {{view app.focusedtextfield}} {{else}} <p {{action foo}}> click here come in text </p> {{/if}} </script>

javascript focus ember.js handlebars.js

No comments:

Post a Comment