How to navigate to next input field after selecting user in type language

I have a form that has some autocomplete (using angular-ui boostrap typeaheade) and some simple input elements. Whenever the user selects from typeahead (via tab, input, or mouse click), I want the focus to move to the next form field. Instead, they must press the tab / enter key twice, once to select, and a second time to move to the next field.

In 0.6.0 version of ui-bootstrap I could achieve this by using typeahead-on-select to call a function like

$scope.onSelect = function() {
    $timeout(function() {
        // code involving element.closes('form').find('button,input,textarea,select')
    });
}

      

However, since upgrading to the current ui-bootstrap version 0.11.2, I have to explicitly set a delay on this timeout. On my dev machine, 10ms works and "feels" fast enough, but this is certainly not reliable:

$scope.onSelect = function() {
    $timeout(function() {
        // code involving element.closes('form').find('button,input,textarea,select')
    }, 10);
}

      

(I can see that the underlying code like "start" included "element [0] .focus ()" in a timeout between 0.6 and 0.11.2.)

Is there a way to achieve my desired behavior without having an ugly explicit timeout delay?

+3


source to share





All Articles