Please see the simple example below; a text box that is bound to a computed observable. My problem is that IE calls the write method twice when the text box is updated. Firefox and other browsers do not appear to have this problem. I have observed this issue in IE 7 & 8.
First of all, am I doing something wrong? If not, what is the recommended approach to deal with it?
<script>
var viewModel = {
myTestVar: "aaa"
};
viewModel.myTest = ko.computed({
read: function () {
return viewModel.myTestVar;
},
write: function (value) {
alert(value);
viewModel.myTestVar = value;
},
owner: viewModel
});
$(document).ready(function () {
ko.applyBindings(viewModel);
});
</script>
</head>
<body>
<input data-bind="value:myTest",type="text" style="width:150px;" />
</body>
The value binding has a special section for dealing with auto-complete in Internet Explorer. This will often cause two writes. You can turn it off if you don't care about auto-complete by adding an attribute to the input:
<input data-bind="value:myTest" type="text" style="width:150px;" autocomplete="off" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With