Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knockout observable element does not updated in IE properly

I have this really simple observable element which for some reason does not update in IE8

<body>
<form data-bind="submit: show">
<input type="text" data-bind="value: someText" />
</form>
<script type="text/javascript">

    var ViewModel = function () {
        var self = this;
        self.someText = ko.observable('initial value');

        self.show = function () {
            alert(self.someText());
            self.someText('');
        }
    }

    ko.applyBindings(new ViewModel());
</script>
</body>

So, when enter is clicked, the value inputed into textbox should be displayed. Everything fine in mozilla, opera, chrome. IE does not see any changes and always alerts with a empty string. Why?
Here you can run this piece of code

like image 334
Vitalii Korsakov Avatar asked Dec 26 '22 19:12

Vitalii Korsakov


1 Answers

Sorry, I should google it carefully. The problem was in different event after which observable element should be updated. Little fix for IE looks like this

<input type="text" data-bind="value: someText, valueUpdate: 'keydown'" />
like image 193
Vitalii Korsakov Avatar answered Jan 13 '23 20:01

Vitalii Korsakov