Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  9] [ 4]  / answers: 1 / hits: 19267  / 10 Years ago, thu, march 27, 2014, 12:00:00

I can't get the enable binding to work in Knockout JS. With the enabled property set to false, the button is not disabled and I can still click it.



see fiddle



<a  class=btn btn-xl btn-primary 
href=#
role=button
data-bind=enable: enabled, click: clicked, visible: isVisible>
<i class=icon-only icon-ok bigger-130></i>
</a>

var ViewModel = function(){
var self = this;

self.enabled = ko.observable(false);
self.isVisible = ko.observable(true);
self.clicked = function(){
alert('You clicked the button');
};
};

$(function(){
var model = new ViewModel();
ko.applyBindings(model);
})

More From » jquery

 Answers
43

Enable binding does not work with anything you want.




This is useful with form elements like input, select, and textarea
It also works with buttons. Like in my example http://jsfiddle.net/5CbnH/1/




But it does not work with your link. You are using twitter bootstrap and they enable/disable their buttons with css classes. So you have to use css binding like this:



data-bind=css: { yourClass: enabled }


Check what class is responsible in bootstrap for showing your button and modify your code accordingly with css binding.


[#71741] Wednesday, March 26, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
charity

Total Points: 503
Total Questions: 98
Total Answers: 125

Location: Mali
Member since Fri, Dec 3, 2021
3 Years ago
;