SteveSanderson/knockout — Issue #183: Doesn't support multi classs on css handler
Author: yestar2000
Created: 2011-10-26 03:40:27+00:00
State: open

When i use below code, it will add the class in multi-times in i change IsPostalCodeEditable value frequently.

css: { 'jq-validation-required jq-validation-length-limit': $item.paymentInfo.IsPostalCodeEditable }

the reason is this handler just support one class.

I think we can update the code to support this function. on toggleDomNodeCssClass: function (node, className, shouldHaveClass) with the parameter classNames : like below:

for (var className in classNames)
{
var hasClass = ko.utils.domNodeHasCssClass(node, className);
if (shouldHaveClass && !hasClass) {
node.className = (node.className || "") + " " + className;
} else if (hasClass && !shouldHaveClass) {
var currentClassNames = (node.className || "").split(/\s+/);
var newClassName = "";
for (var i = 0; i < currentClassNames.length; i++)
if (currentClassNames[i] != className)
newClassName += currentClassNames[i] + " ";
node.className = ko.utils.stringTrim(newClassName);
}
}