【问题标题】:angular bootstrap typeahead close select角引导输入提前关闭选择
【发布时间】:2015-04-14 11:27:12
【问题描述】:

我希望在表单提交的值不在列表中时关闭选择列表(使用 typeahead-focus-first)。我以typeahead plunker 示例为起点。

当用户按下回车键时,storeItem 函数会触发,但列表不会关闭。

<form ng-submit="storeItem()">
  <input type="text"
    typeahead="state for state in states | filter:$viewValue | limitTo:8" 
    typeahead-focus-first="false"/>
</form>

提交函数:

$scope.storeItem = function() {
   $scope.selected = Date.now();
};

查看完整的 plunker here

如何关闭列表,同时保持输入值和列表不变?

【问题讨论】:

标签: javascript angularjs angular-ui-bootstrap angular-ui-typeahead


【解决方案1】:

您似乎发现了一个错误。感兴趣的区域在 typeahead 指令中 - element.bind('keydown' 方法。当按下 enter 或 tab 并且没有选择任何内容时,有逻辑不关闭下拉列表:

// if there's nothing selected (i.e. focusFirst) and enter is hit, don't do anything
if (scope.activeIdx == -1 && (evt.which === 13 || evt.which === 9)) {
  return;
}

输入元素失去焦点,弹出窗口没有关闭。你应该在repo 上打开一个问题。

【讨论】:

  • 谢谢@rob-j,我已经done that。如果他们确认这是一个问题,我会将您的回答标记为已接受。
  • 能否在 Github 上提供该行的链接(通过单击行号获得)?我在最新版本中找不到它。
  • @DmitriZaitsev Link 到线。
  • 我明白了。这可能是有意的 - 请注意此处的类似行为material.angularjs.org/#/demo/material.components.autocomplete
  • 材料版本似乎没有表现出相同的行为。 ng-bootstrap 版本的问题是,输入元素失去焦点,下拉菜单保持打开状态,材料版本没有失去焦点。
猜你喜欢
  • 1970-01-01
  • 2021-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多