This web page works as expected on Chrome and Firefox (in Windows and Linux). It does not work in IE11.
It appears that the 'checked' status of the check box is updated AFTER the 'change' event occurs; but only on IE11. This results in 'checked' being shown in the edit box when the check box is unchecked, and vice versa.
The only solution I've found is, instead of using the observable boolean value, to use the check box itself and query it's 'checked' property: $('#CheckBox').prop('checked').
Here is the test web page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!--This is needed just to get this page to load on IE11-->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Check Box Issue</title>
<script type='text/javascript' src='https://code.jquery.com/jquery-2.2.4.min.js'></script>
<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-min.js'></script>
</head>
<body>
<p>Click check box to toggle text</p>
<input id="CheckBox" type="checkbox" data-bind="checked:box,event:{change:boxChange}"><input type="text" data-bind="value:val">
<script>
var KoCheckboxIssue = (function () {
function KoCheckboxIssue() {
var self = this;
self.box = ko.observable(false);
self.val = ko.observable('Unchecked');
ko.applyBindings(self);
}
KoCheckboxIssue.prototype.boxChange = function () {
var self = this;
if (self.box()) {
self.val('Checked');
}
else {
self.val('Unchecked');
}
};
return KoCheckboxIssue;
}());
var koCheckboxIssue;
$(document).ready(function () {
koCheckboxIssue = new KoCheckboxIssue();
});
</script>
</body>
</html>
Does anyone know if there's a way to use the observable as shown?
Thanks.
PS: That JavaScript was generated from TypeScript.