Toggle buttons

Binding to Bootstrap toggle button.

Examples

Html markup

<button class="btn btn-info" data-bind="toggle: isToggled">Toggle button</button>

Viem model

function ButtonsExampleViewModel() {
    //...

    this.isToggled = ko.observable(false);
}

Options

data-bind="toggle: value"

Radio buttons

Two-way binding to Bootstrap radio buttons. Default Knockout checked binding doesn't work with Bootstrap's buttons, so you can use this binding

Examples

Html markup

<div class="btn-group form-group" data-toggle="buttons" data-bind="radio: radioValue">
    <label class="btn btn-primary">
        <input type="radio" name="options" value="A" />
        A
    </label>
    <label class="btn btn-primary">
        <input type="radio" name="options" value="B" />
        B
    </label>
    <label class="btn btn-primary">
        <input type="radio" name="options" value="C" />
        C
    </label>
</div>

View model

function ButtonsExampleViewModel() {
    //...

    this.radioValue = ko.observable();
}

Options

data-bind="radio: value"

Checkbox buttons

Two-way binding to Bootstrap checkbox buttons. Default Knockout checked binding doesn't work with Bootstrap's buttons, so you can use this binding

Examples

A value:
B value:

Html markup

<div class="btn-group form-group" data-toggle="buttons" data-bind="checkbox: checkboxArray">
    <label class="btn btn-primary">
        <input type="checkbox" value="A" />
        A
    </label>
    <label class="btn btn-primary">
        <input type="checkbox" value="B" />
        B
    </label>
    <label class="btn btn-primary">
        <input type="checkbox" value="C" />
        C
    </label>
</div>

<div class="btn-group form-group" data-toggle="buttons">
    <label class="btn btn-primary">
        <input type="checkbox" data-bind="checkbox: checkboxValueA" />
        A
    </label>
    <label class="btn btn-primary">
        <input type="checkbox" data-bind="checkbox: checkboxValueB" />
        B
    </label>
</div>

View model

function ButtonsExampleViewModel() {
    //...

    this.checkboxArray = ko.observableArray();
        
    this.checkboxValueA = ko.observable(true);
        
    this.checkboxValueB = ko.observable(false);
}

Options

data-bind="checkbox: value"