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

this.$() failing when tagName is set to empty #4837

Closed
responsis opened this issue May 8, 2014 · 8 comments
Closed

this.$() failing when tagName is set to empty #4837

responsis opened this issue May 8, 2014 · 8 comments
Labels

Comments

@responsis
Copy link

I know jQuery is being phased out as a dependency soon, but this cost me an hour:

http://jsfiddle.net/6Evrq/73/

this.$() fails when tagName === ''

I'm not sure what could be done about this, but thought I would report it anyway.

@GetContented
Copy link

I think that's expected behaviour. this.$() gets the HTML element... there isn't one... so what would you expect it to do?

@GetContented
Copy link

You should probably be using a span tag IMO. I guess your expectation was that this.$() would get you the HTML node, (ie in your case the textNode), but that's not what it does. It gets the HTML element.

@responsis
Copy link
Author

I understand the issue, and it makes sense, but maybe there should be an error message or something? I'm not sure exactly, but It would be good to save someone else the time of finding out like i did.

Maybe even just a note in the docs?

@GetContented
Copy link

A component should have an element. It's a bit of a strange use case to have no tag on a component, isn't it? I'm pretty surprised anyone would actually do that.

I don't think it's the framework's job to tell you if you're doing something not quite correctly. That's what an IDE or documentation or other programmers helping you is for. Otherwise you'd end up with a framework which had every possible error anyone had ever made in it bloating out the codebase.

@responsis
Copy link
Author

This is applicable to all Views, not just components. An example use case is if you had a view/component that contains two tr tags, any wrapper around them will break clean DOM.

That said, I'm not sure what the ember policy in this kind of issue is, hence while I opened and issue instead of submitting a PR. Happy to close if this is out of scope and such.

@stefanpenner
Copy link
Member

what should $() return if there is no tagName? Your immediate children could be a collection, is that would this.$() should return then? This is strange, because if it is a collection, that collection might grow/shrink, without the correct hooks this just gets pretty confusing.

@andrasz
Copy link

andrasz commented May 28, 2014

Hi! I've just ran into this issue, and I agree with @responsis that this is a valid scenario. I think there is no problem with the this.$() returning a collection. If I'm not mistaken it already returns a jQuery object which can be interpreted as a collection.

I would expect it to return the child elements in the jQuery object if the tagName property is ''.

@trek
Copy link
Member

trek commented Jul 15, 2014

There is a way to have no tag on a view (inheriting from _MetamorphView) but that is private and not recommended generally (since _MetamorphView will be gone soon) when HTMLBars lands.

Until then, we just don't support "" as a tagName.

See discussion here

@trek trek closed this as completed Jul 15, 2014
@trek trek added the HTMLBars label Jul 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants