Ok, I solved the problem using hasfocus binding:
(function() { var vm = { text: ko.observable(), items: ko.observableArray([]), isFocused: ko.observable() } vm.addItem = function() { vm.items.push(vm.text()); vm.text(null); vm.isFocused(true); } ko.applyBindings(vm); }());
HTML:
<input type="text" data-bind="value: text, hasfocus: isFocused" /> <a href="#" data-bind="click: addItem">Send</a> <ul data-bind="foreach: items"> <li data-bind="text: $data"></li> </ul>
Working example: http://jsfiddle.net/srJUa/2/
Not sure if this is the best way.
tugberk
source share