mercredi 6 décembre 2017

Select an input after its inserted using `Ember.run`

I'm building a list of text inputs based on an array on my model. On newline I'd like to insert a new text field and then select it. I'm trying to do this with Ember.run.scheduleOnce, but the function I provide is never called.

I've reopened the textfield to expose a data-index attribute binding, and in my template am rendering:


  


In my controller:

actions: {
  insertEntry(index){
    // This works fine and a new textfield is added.
    this.get('model.entries').addObject({text: 'Example'});

    // This doesn't seem to work at all. 
    Ember.run.scheduleOnce('afterRender', this, function(){
      console.log("This is never logged");
      $(".field--entry[data-index='" + index + 1 + "']").focus();
    });
  }
}




Aucun commentaire:

Enregistrer un commentaire