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

When elAttribute=class, it should check if the previousValue is undefined #191

Open
kadishmal opened this issue Oct 8, 2014 · 3 comments

Comments

@kadishmal
Copy link

Basically this line https://github.com/theironcook/Backbone.ModelBinder/blob/master/Backbone.ModelBinder.js#L400 is not completely correct:

if(!_.isUndefined(previousValue) || !_.isUndefined(currentValue)){
    previousValue = this._getConvertedValue(Backbone.ModelBinder.Constants.ModelToView, elementBinding, previousValue);
    el.removeClass(previousValue);
}

It should be:

previousValue && el.removeClass(previousValue);

That is it should check whether the previousValue is not undefined. If it is, then el.removeClass(undefined) will remove all the classes previously defined for some other purposes. Imagine I have an icon defined as <i class="fa fa-envelope"/>. If previousValue=undefined, then it will remove fa fa-envelope classes completely so the element will end up being <i class=""/>.

@platinumazure
Copy link
Contributor

I think this is caused by a change in the behavior of removeClass in jQuery, incidentally.

@amakhrov
Copy link
Contributor

amakhrov commented Aug 8, 2015

In which version of jquery removeClass(undefined) removes all the element classes? I was not able to reproduce it with 1.10.2, 1.11.3

@platinumazure
Copy link
Contributor

I think I had observed that behavior somewhere in the 1.8.x series. Maybe they've changed it again...? I guess I don't know if this issue is still valid.

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

No branches or pull requests

3 participants