This is a migrated thread and some comments may be shown as answers.

Conditional class binding needed (or workaround)

2 Answers 278 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Luc
Top achievements
Rank 1
Luc asked on 19 Apr 2012, 03:36 PM
Hi,

Over the past few days I've been struggling to get KendoUI MVVM bindings to work for the specific use case where you want to conditionally modify the class of an HTML element. At this point in time, Kendo MVVM doesn't support this use case.

I've even tried to create custom bindings, but there is a problem when they are used within templates. I've been offered an undocumented workaround by the KendoUI team, but I've also been warned that it might eventually break in future releases, so I don't feel comfortable using it.

I'd like to hear from others who might have found out of the box solutions to this problem.

P.S.: I know there is a style binding in Kendo MVVM, but this puts styling information in the code, and I don't want this. I want my style informartion to remain in css files.

Thank you

2 Answers, 1 is accepted

Sort by
0
Jeff
Top achievements
Rank 1
answered on 27 Sep 2012, 04:15 AM
The best work-around I've found is: data-bind="{attr:{class:someObservableFunction}}"

But I've noticed that this binding doesn't work when rendering in a page in IE compatibility mode (so would probably fail in older versions of IE).  Does anyone know of a better way to do this?

I agree with the author of the original post that class binding is probably more useful (or at least cleaner) than style binding.
0
Zachary
Top achievements
Rank 1
answered on 01 Jan 2014, 02:00 AM
I agree that class bindings are sorely missing. There is a UserVoice suggestion here: Add an MVVM css binding
Tags
MVVM
Asked by
Luc
Top achievements
Rank 1
Answers by
Jeff
Top achievements
Rank 1
Zachary
Top achievements
Rank 1
Share this question
or