Fergal Moran
Fergal Moran

Reputation: 4634

knockout.js bind bootstrap btn-group

I'm wondering if it's possible to bind the selected value in a Twitter bootstrap radio btn-group to an observable in knockout.js?

In my case, I'm binding the group to an observableArray like so

  <div class="btn-group" data-toggle="buttons-radio" data-bind="foreach: myItemTypes">
    <button class="btn active" data-bind="html: Value, Id: Key">${ Description }</button>
  </div>

Any guidance?

Cheers,

Fergal.

Upvotes: 5

Views: 5336

Answers (2)

cuhuak
cuhuak

Reputation: 498

See also checkedButtons bindingHandler

Upvotes: 7

John Earles
John Earles

Reputation: 7194

Here is an example of how this could be done:

http://jsfiddle.net/jearles/vu8pk/

By using the css binding we can dynamically turn the "active" class on/off based on the selected observable for each button.

Upvotes: 11

Related Questions