Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attributesBindings does not set id in 1.13 #11871

Closed
Serabe opened this issue Jul 23, 2015 · 6 comments · Fixed by #11889
Closed

attributesBindings does not set id in 1.13 #11871

Serabe opened this issue Jul 23, 2015 · 6 comments · Fixed by #11889

Comments

@Serabe
Copy link
Member

Serabe commented Jul 23, 2015

The following code does not work in 1.13 but does in 1.12:

export default Ember.Component.extend({
  attributeBindings: [
    'tagId:id', // Not working
    'hi:my-attr', // working
  ],
  tagId: 'my-id',
  hi: 'hola',
});
@Serabe
Copy link
Member Author

Serabe commented Jul 23, 2015

For reference, thank to @SaladFork, attributeBindings in:

@Serabe
Copy link
Member Author

Serabe commented Jul 23, 2015

On the other hand, if the component gets called like {{my-component id="whatever"}} the element gets the whatever id.

@Serabe
Copy link
Member Author

Serabe commented Jul 23, 2015

The problem seems to be in this line. I need to do something like this:

{{my-component object=object}}

with the my-components id attribute depending on a (computed) property of object (the CP does not depend on any other attribue). I tried setting directly the elementId in didInitAttrs, but it seems it was too late to change it.

didInitAttrs() {
  this.elementId = this.get('object.idForComponent');
}

On the other hand, doing that in init works as expected.

What is the official and supported way to do this?

@pixelhandler
Copy link
Contributor

attributeBindings are a feature of Ember.View (deprecated) and not are not documented whether or not the same feature will be supported on Ember.Component.

This does appear to be a (regression) bug for v1.13.x as this did work in v1.12. I someone will need to confirm whether an undocumented use of attributeBindings even in 1.12 should still work in 1.13.

@stefanpenner
Copy link
Member

So just a headsup, we don't support id's changing after initial render. Although I believe we do support bindings used to populate it on initial render.

Someone should likely verify my above statements.

It may be the case, that timings changed preventing the ID from being set at the right time. (that is my guess)

@rwjblue
Copy link
Member

rwjblue commented Jul 24, 2015

attributeBindings is a supported and public API for Ember.Component. The issue here is that the id attribute is set to the elementId (essentially hard coded) and does not look for it in attributeBindings. We specifically make {{foo-bar id="asdfadsf"}} work by grabbing id out of attrs here.

We could likely fix that in our handling of attributeBindings. Essentially moving this above here.

Working on a test + PR...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants