dimanche 21 décembre 2014

ember autofocus component after insertion into DOM

I want to display an input field, and immediately autofocus it upon clicking a button. Im still new to Ember so i am not sure this is the correct approach, but I tried to wrap as an ember component


template



{{#if showCalendarForm}}
{{new-calendar focus-out='hideNewCalendar' insert-newline='createCalendar'}}
{{else}}
<button class="btn btn-sm btn-primary" {{action "showNewCalendar"}}>New</button>
{{/if}}


new-calendar component handlebars:



<div class="input-group">
{{input
class = 'form-control'
id = 'newCalendar'
type = 'text'
placeholder = 'New calendar'
value = calendarName
action = 'createCalendar'
}}
</div>


new-calendar component js



import Ember from 'ember';

export default Ember.Component.extend({
didInsertElement: function() {
this.$().focus();
}
});


When I click the button, the text field is displayed, but autofocus and hitting enter doesnt work





Aucun commentaire:

Enregistrer un commentaire