仅当显式选择了行时才提前关闭Tab-ui uis-bootstrap [英] Tab-off ui-bootstrap typeahead only when row is explicitly selected

查看:58
本文介绍了仅当显式选择了行时才提前关闭Tab-ui uis-bootstrap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了这个 jsBin ,以演示我遇到的问题.如果您去这里,请尝试键入五"并继续.自然的反应是键入五",然后按tab键;如果要五百",则向下箭头一次;但是,在这种情况下,您必须键入五",然后在不单击任何其他选项的情况下直接按Escape键或直接将鼠标移出框

I've created this jsBin to demonstrate the issue I'm having. If you go here, try type "Five" and move on. Your natural reaction would be to type "Five" and then press tab, and if you wanted "Five-Hundred," you'd arrow-down once; however, in this case, you have to type "Five" and then either press escape or physically mouse out of the box without clicking any of the other options

因此,基本上,当您使用typeahead时,如果当前条件至少有一个匹配结果,请按tab进行选择.我的预期行为是,键入时,当前选择的选项正好是您键入的内容,如果要获得其他结果之一,则必须向下箭头一次或多次.

So, basically, when you're using typeahead, if there is at least one matching result for your current criteria, pressing tab will select it. My expected behavior is that as you type, the current selected option is exactly what you're typing, and if you want one of the other results you must down-arrow one or more times.

这是jsBin中的代码:

Here is the code that's in the jsBin:

<div ng-controller="TestController">
  <div>
    {{selected}}
  </div>
  <input type="text" ng-model="selected" typeahead="item for item in typeaheadOptions | filter:$viewValue">
</div>

和JavaScript:

And the JavaScript:

var app = angular.module('app', ['ui.bootstrap'])

.controller('TestController', function($scope) {
  $scope.typeaheadOptions = [
    'One','Two','Three','Four','Five-Hundred','Fifteen','Fourteen','Fifty','Six','Seven','Eight','Nine','Ten'
  ]
});

推荐答案

我最终修改了ui-bootstrap以使其达到期望的效果.

I ended up modifying ui-bootstrap to work how I want it to.

我在指令中添加了mustMouseDownToMatch属性/属性,例如:

I added a mustMouseDownToMatch property/attribute to the directive, like:

<input type="text" ng-model="selected" typeahead="item for item in typeaheadOptions | filter:$viewValue" typeahead-mouse-down-to-match="true">

和javascript:

And the javascript:

var mustMouseDownToMatch = originalScope.$eval(attrs.typeaheadMouseDownToMatch) ? originalScope.$eval(attrs.typeaheadMouseDownToMatch) : false;

我还添加了此功能,该功能会将当前文本放入预输入列表的第一项中,并将其作为选定项:

I also added this function which will put the current text into the first item of the typeahead list, and make it the selected item:

var setFirstResultToViewValue = function (inputValue) {
    scope.matches.splice(0, 0, {
        id: 0,
        label: inputValue,
        model: inputValue
    });

    // set the selected item to the first item in the list, which is this guy
    scope.activeIdx = 0;
}

然后在typeahead指令的getMatchesAsync调用中调用:

And that is called in the getMatchesAsync call in the typeahead directive:

var getMatchesAsync = function(inputValue) {
// do stuff
    $q.when(parserResult.source(originalScope, locals)).then(function(matches) {
        // do stuff
        if (matches.length > 0) {
             // do stuff
        }
        if (mustMouseDownToMatch) {
            setFirstResultToViewValue(inputValue);
        }
        // do stuff
  };

这篇关于仅当显式选择了行时才提前关闭Tab-ui uis-bootstrap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆