3

I have been following the getting started guide for ember.

I have come to the parts that deal with editing and removing items and have come across a problem that seems to occur in chrome but not firefox.

The custom component "edit-todo" has 2 events that are linked to the action "acceptChanges"

{{#if isEditing}}
  {{edit-todo class="edit" value=title focus-out="acceptChanges" insert-newline="acceptChanges"}}
{{else}}


The "acceptChanges" action fires the "removeTodo" action if the item's title is empty

acceptChanges: function () {
  this.set('isEditing', false);

  if (Ember.isEmpty(this.get('model.title'))) {
    this.send('removeTodo');
  } else {
    this.get('model').save();
  }
},
removeTodo: function () {
  var todo = this.get('model');
  todo.deleteRecord();
  todo.save();
}

If you edit an item, delete the text and press enter or switch focus, the item gets deleted. This works perfectly for me in Firefox.

In Chrome however, the acceptChanges action is firing twice if you delete the title and press enter. When the DOM updates to remove the item, the acceptChanges action is fired again, presumably because it loses focus.

This jsbin shows the problem, it is essentially just the code from the guide with some console logs. If you edit the item "BBB", delete the text and press enter, the data for "CCC" is deleted also. It remains in the DOM but you can no longer interact with the item and the items remaining count is wrong. If you open ember inspector in the developer tools you can see that the only data left is for the item "AAA".

I am wondering if this is a bug with ember, with ember-data, with chrome, or if it is expected behaviour that I should be checking for in my js?

I am using Chrome Version 26.0.1410.63

PrestaShopDeveloper
  • 3,110
  • 3
  • 21
  • 30
cutts
  • 574
  • 1
  • 5
  • 20
  • To me this looks like unexpected behaviour. On my TodoMVC App I have the same situation (I just don't realized it). Also, you can't edit the item after the one you previously deleted (In firefox everything is fine). – Mythli Oct 24 '13 at 06:42
  • Just tested this on my windows box with Chrome Version 30.0.1599.101 m. Same results. – cutts Oct 24 '13 at 08:11
  • This question has been raised as an issue in ember.js on github: https://github.com/emberjs/ember.js/issues/3741 – cutts Nov 27 '13 at 10:21
  • @rpcutts Have you been able to find some solution to this or is this a bug with Ember/Chrome ? I also ran into the same issue - everything is fine with Firefox and IE-11 as well. – ykesh Mar 29 '14 at 16:52
  • @ykesh see the github issue link in my previous comment. There's a bit more info there about how to handle this. I'm waiting for that issue to be closed out before updating this question. – cutts Mar 31 '14 at 10:02
  • 1
    Yeah, this is a bug. The 'removeTodo' action gets sent twice in the same run loop. In the TodoMVC.com version we handle this like so: https://github.com/tastejs/todomvc/blob/gh-pages/architecture-examples/emberjs/js/controllers/todo_controller.js#L21-L25 – bantic Apr 13 '14 at 19:41

0 Answers0