event Change in Checkbox ( Firefox and Google Chrome)

35 views
Skip to first unread message

Сергей Егоров

unread,
May 14, 2015, 5:40:24 AM5/14/15
to knock...@googlegroups.com
I have a checkbox with event change and 

  <input type="checkbox" class="checkMy" data-bind="checked:checkAnimal,event:{change:accomodationCalc}">  

function ...
 var self = this;
 this.checkAnimal = ko.observable(true);
this.accomodationCalc = function(that, event) {
       console.log( this.checkAnimal());    
       // In firefox i geted false;  and that's normal
      // But in chrome i geted true, Why???
};

I use possible solution, that's to use click event  with return true in the function
  <input type="checkbox" class="checkMy" data-bind="checked:checkAnimal,event:{click:accomodationCalc}">  

this.accomodationCalc = function(that, event) {
       console.log( this.checkAnimal());    
       // In firefox  // FALSE
      // In chrome // FALSE
};

Michael Best

unread,
May 14, 2015, 8:51:15 PM5/14/15
to knock...@googlegroups.com
Don't add an extra event handler to the checkbox. Instead subscribe to the observable:

checkAnimal.subscribe(function(value) {
    // do something
});

-- Michael
Message has been deleted

Сергей Егоров

unread,
May 15, 2015, 2:46:04 AM5/15/15
to knock...@googlegroups.com
Don't add an extra event handler to the checkbox. Instead subscribe to the observable:

checkAnimal.subscribe(function(value) {
    // do something
});
 
Thank you very much Michael!!! You made my day!
Reply all
Reply to author
Forward
0 new messages