Example taken from the documentation and stuck to a fiddle doesn't work. Code snippet for completeness:
<p>Login name: <input data-bind="textInput: userName" /></p>
<p>Password: <input type="password" data-bind="textInput: userPassword" /></p>
ViewModel:
<pre data-bind="text: ko.toJSON($root, null, 2)"></pre>
<script>
ko.applyBindings({
userName: ko.observable(""), // Initially blank
userPassword: ko.observable("abc") // Prepopulate
});
</script>
I've tried it in an incognito window thinking that some browser extension might be messing with it. No luck.
Expected behavior is that viewModels's JSON dump should be updated with each keystroke in any of the input fields change.
If I switch to value binding instead of textInput it does update whenever input focus changes.
Has anyone encountered this?
If you are stuck on an older version of Knockout you can use valueUpdate
<input data-bind="value: firstName, valueUpdate:'afterkeydown'" />
https://stackoverflow.com/a/4391419/1058292
The textInput
binding was added in a later version of Knockout.JS (3.2.0).
Add the updated library to your fiddle and it works.
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