I am trying to set focus on an input with knockout after the click event is fired but couldn't find a clean way to handle it without coupling with the DOM. Here is the JS code I have:
(function() {
var vm = {
text: ko.observable(),
items: ko.observableArray([])
}
vm.addItem = function() {
vm.items.push(vm.text());
vm.text(null);
}
ko.applyBindings(vm);
}());
This is my DOM:
<input type="text" data-bind="value: text" />
<a href="#" data-bind="click: addItem">Send</a>
<ul data-bind="foreach: items">
<li data-bind="text: $data"></li>
</ul>
Here is the JsFiddle sample: http://jsfiddle.net/srJUa/1/
What I want it to set focus on the input after the vm.addItem
is completed. Any idea how this can be done cleanly, for example with a custom knockout binding?