-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Html classes repeated when binding to itemViewClass's attributes #100
Comments
I added failing test for the issue. The biggest problem with this are not duplicated classes, but the fact that after a few attribute changes old classes are not always removed, so you end up with mixed new and old classes. It seems that the cause of the problem is using bindings to parent view (or probably more generally - multiple chained bindings), when you remove bindings and use direct paths such as "parentView.parentView.content.foo" it works correctly. |
I thought that the issue lays somewhere inside _applyClassNameBindings, but it's actually caused by how bindings work. The problem is, classNameBindings generate a class name twice if bindings chain is used (by chain I mean binding through at least 2 bindings). Here is a view that shows the problem: TemplateTests.MyView = SC.View.extend({
foo: "foo",
barBinding: "foo",
bazBinding: "bar",
quxBinding: "baz",
fooBarBinding: "qux",
fooBazBinding: "fooBar",
classNameBindings: ["fooBaz"],
classNames: ["child"]
}); Interestingly, the above view produces Essentially the problem with mixed classes looks like that:
So the quick fix is to make array of class names unique here: https://github.com/sproutcore/sproutcore20/blob/2fb9d8c250/packages/sproutcore-views/lib/views/view.js#L756, but it does not fix the real issue with binginds. |
I commited my quick nasty fix for it if someone needs it fixed now :) |
Seems like the actual issue is that all bindings need to be synced before _applyClassNameBindings is run. |
@drogus, are you still seeing this issue on master? |
Now that I think about it, this sounds similar to an issue that @ebryn ran across recently. |
Yeah, this looks pretty similar to something I saw the other day. Thanks @wagenet, will try to fix this next week. |
I happened to bump into this issue and looked a bit into it. My interpretation is that there's actually two problems, both triggered by either an explicit rerender call or a view being removed and then re-appended to the DOM:
I was able to fix the problems I was seeing by changing said observer to also remove oldClass from classNames, and in the setup in _applyClassNameBindings only push dasherizedClass to classNames if not already there. I can try to find the time to do a proper commit & pull request later, hopefully by next week. |
Should be fixed in master now. |
Great, I can confirm my problem number 2 is now gone. However, problem number 1 still stands. I wrote a test case and a fix, pull request here: https://github.com/sproutcore/sproutcore20/pull/224 (I guess it's really a separate issue in the end, not directly related to this one) |
I will try to add failing test for this, but for now here is error reproduced on jsfiddle: http://jsfiddle.net/b4RMr/10/
Both boxes have classes from bindings repeated twice. When you change classNameBinding to "parentView.foo" instead of just "foo" it starts to work correctly.
The text was updated successfully, but these errors were encountered: