Assertfail

All Posts assertfail

View the Blog on GitHub wallymathieu

Spending hours on trying to figure out why it does not check

31 Jul 2012

Yesterday I spent hours trying to figure out why a checkbox did not get checked (visually). When debugging the knockout code, it was clear that the DOM elements got checked. They did not update visually until another checkbox got checked. I tried other methods of checking the checkbox (both setAttribute and jquery) to no affect. What was even weirder is that it works the same in both chrome and IE.

To reproduce, click on the first checkbox and then the second in this fiddle.

I got the question if I had a click event handler from steal my code.

Turns out that the reason for this behavior is that I had a click event handler on a parent DOM element. By having the click handler return true the problem was resolved.

I still don’t understand why it works like this.

Tags

  • javascript
  • knockout
  • Comments or errors? Fork post and do a pull request on github