24

I have some html like the following:

<div class="control-group">
    <input type="text" data-bind="value: $data.DealCode" name="DealCode" class="input-mini" />
</div>

However, ifnot: $data.DealCodeIsValid, I need to render the following:

<div class="control-group error">
    <input type="text" data-bind="value: $data.DealCode" name="DealCode" class="input-mini" />
</div>

Note the additional class "error" in the div. Is there a way to do that with knockoutjs?

Andrew
  • 18,680
  • 13
  • 103
  • 118
devlife
  • 15,275
  • 27
  • 77
  • 131

1 Answers1

36

Something like

<div data-bind="css: {'control-group': true, error: (!$data.DealCodeIsValid)}">

Check here for more info

jon
  • 728
  • 5
  • 12