Andrei
Andrei

Reputation: 44550

Knockout initial binding

How can I use knockout if my html is already rendered. I'd like to apply binding on checkbox: when checkbox is checked I want my textarea be enabled and vice versa.

How can I achieve this?

Upvotes: 0

Views: 135

Answers (2)

alecasciaro
alecasciaro

Reputation: 155

I don't understand

How can I use knockout if my html is already rendered

but if your question is How can i enabled a textbox according to checkbox state you can try this :

<div><input type="checkbox" data-bind="checked: isTextBoxEnabled"/>Enable textbox</div>
<div><input type="input" data-bind="enable: isTextBoxEnabled"/></div>

var ViewModel = function() {
        var self = this;
        self.isTextBoxEnabled = ko.observable(true);
    };

ko.applyBindings(new ViewModel());

http://jsfiddle.net/8evLv/

Upvotes: 1

Anders
Anders

Reputation: 17554

You shouldnt do it, but it works.

Just add the data-bind attribute to the elements. Lists of checkboxes etc wont work though

Upvotes: 1

Related Questions