Pinaki
Pinaki

Reputation: 93

Binding issues in Knockout

i am pretty new to knockoutjs. I have a set of buttons clubbed under different fieldsets. I have bound the buttons to a single observable to enable or disable the buttons. On clicking a button under a fieldset i want only the set of buttons under that fieldset to be disabled. How do i do it through knockout.

I have created a fiddle for this here trying to explain my problem

Thanks.

<div data-bind="foreach: items">
<fieldset>
    <ul data-bind="foreach: $data.item">
        <li class="list">
            <input type="button" data-bind="value: $data.title, enable: $root.isEnabled, click: $root.buttonClicked"
            />
        </li>
    </ul>
</fieldset>

Upvotes: 3

Views: 659

Answers (1)

Gaurav
Gaurav

Reputation: 8487

Have a look at this working fiddle. Hope it will helps you for what you want to achieve.

Below is the html code, notice here we used disable binding to disable buttons.

  <ul data-bind="foreach: Buttons">
    <li class="list">
       <input type="button" data-bind="value: Title, 
                                       click: $root.SetSelectedButton, 
                                       disable: $root.SelectedButton() === $data"
        />
     </li>
   </ul>

EDIT

Sorry i missed your point in which you mentioned that you want to disable set of buttons. Here is the another fiddle which is the next version of the previous fiddle. In this fiddle you can enable or disable the set of buttons :

Updated working fiddle

Upvotes: 2

Related Questions