【问题标题】:ui-select-no-choice message is displayed if the text length is zero如果文本长度为零,则显示 ui-select-no-choice 消息
【发布时间】:2020-04-07 01:23:06
【问题描述】:

我正在使用 ui-select 来实现自动完成功能,如果没有搜索条件的结果,那么我正在使用 ui-select-no-choice 向用户显示消息。

 <div class="form-group">
    <label class="Label">
      Select details
    </label>
    <ui-select ng-model="configItem.details" id="details" multiple class="form-control" theme="bootstrap" title="Choose details" reset-search-input="true" close-on-select="true" spinner-enabled="true" spinner-class="ui-select-spin">
      <ui-select-match placeholder="Search.." class="ui-select-match">{{$item.Name}}</ui-select-match>
      <ui-select-choices class="ui-select-choices" refresh="details($select.search)" refresh-delay="0" minimum-input-length="3" repeat="detail.ID as detail in details| filter: $select.search | limitTo: 100">
        <div ng-bind-html="detail.Name | highlight: $select.search"></div>
      </ui-select-choices>
      <ui-select-no-choice>
        No Information found
      </ui-select-no-choice>
    </ui-select>
  </div>

 $scope.details = function (search) {
        if (search.length >= 3) {
          AddUpdateService.getAllData(search)
        }
}

由于我的数据集很大,我使用 minimum-input-length="4" 所以不会有很大的结果,但我面临的问题是如果用户没有输入任何数据,那么 ui-select-no-choice正在显示不正确的消息。如果用户输入超过 4 个字符,我需要显示消息。

这是关于x图标对齐的截图

【问题讨论】:

  • 能多加些html和js相关的代码
  • 使用 HTML 代码和后端 API 调用的已编辑帖子正在正确返回数据。

标签: angularjs autocomplete ui-select


【解决方案1】:

您可以根据需要使用 ng-class 来隐藏它。

好像

<ui-select-no-choice ng-class="{ 'hide': $select.search.length < 5 }">
        No Information found
      </ui-select-no-choice>

这里是演示 - https://next.plnkr.co/edit/PjuhUR?preview 希望对您有所帮助。

update:: 不输入任何内容时隐藏以前的结果

    <ui-select-choices repeat="color in availableColors | filter: $select.search" 
ng-class="{ 'hide': $select.search.length < 1 }">

【讨论】:

  • 谢谢...这有帮助。此外,我确实注意到 ui-select 会记住以前的搜索结果并加载下拉列表,如果没有输入任何内容。我不想要那个功能。我如何禁用它??
  • 我已经更新了答案,只需使用相同的逻辑进行选择
  • 感谢您的帮助。另一个问题是,取消选定项目的选项未正确对齐(换句话说,x 图标必须放置在选定项目的中心或底部)。我们如何解决这个问题?我用截图更新了原始帖子
  • 能否更新演示中的代码以重现问题?
猜你喜欢
  • 1970-01-01
  • 2017-09-28
  • 2016-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多