emberjs/ember.js — Issue #425: "dynamic" assignment of a view's elementId breaks EventDispatcher
Author: siebertm
Created: 2012-01-23 12:21:40+00:00
State: open

Scenario is as follows:

I have a view with a dynamic elementId (generated automatically). I want a child view with an element id of "-suffix".
To accomplish that, I use the following code:

```javascript
var template = '{{view "Ember.View" elementIdBinding="boundViewId"}}';

view = Ember.View.create({
template: Ember.Handlebars.compile(template),
boundViewId: "templateViewTestBoundId"
});
```

Now, this seems to work, the DOM id of the generated child view is correct, but no events on that view are fired. Turns out that the view is added to Ember.View.views with a default generated GUID, THEN the elementId is changed (before rendering), and the dispatcher can't find the view in Em.View.views anymore.

As a result, when I destroy the view, it tries to delete the *new* elementId from Em.View.views.

To illustrate the problem, you can use the following test:

```javascript
var template = '{{view "Ember.View" elementIdBinding="boundViewId"}}';

view = Ember.View.create({
template: Ember.Handlebars.compile(template),
boundViewId: "templateViewTestBoundId"
});

view.append();

var childView = nthChild(view, 2);
var id = childView.$()[0].id;
equals(id, 'templateViewTestBoundId', 'precond -- id of childView should be set correctly');

equals(Ember.View.views[id], childView, 'childView with passed ID (via elementIdBinding) is registered with Ember.View.views so that it can properly receive events from RootResponder');
// that one fails ^^
```

Is this even supported? I think it should be...