-->

UI-Select reset-search-input does not work

2019-07-03 06:54发布

问题:

Please see my code below, when a choice is select from an input by typing something in i.e "Fr" and all the countries starting with France would appear, however after the input is selected the input field does not get cleared

 <ui-select multiple
                       ng-model="quote.targetLanguage"
                       reset-search-input="true"
                       theme="bootstrap"
                       ng-disabled="disabled"
                       close-on-select="false"
                       style="width: 800px;">
                <ui-select-match placeholder="Select person...">
                    {{$item.language}}
                </ui-select-match>
                <ui-select-choices repeat="lang in controllersData.languages | filter: $select.search">
                    <div ng-bind-html="lang.language | highlight: $select.search"></div>

                </ui-select-choices>
            </ui-select>

回答1:

You can set it at the global level using the uiSelectConfig constant like:

app.config(function(uiSelectConfig) {
  uiSelectConfig.resetSearchInput = true;
});

It worked for me.



回答2:

The issue is still occurring in version 0.11.2.

As Dayan suggested in the comments, resetting the search in the on-select event solves it:

<ui-select multiple ng-model="numbers" on-select="numberSelected($select)">
...
</ui-select>

Then in your controller/directive:

scope.numberSelected = function ($select) {
    // clear search text
    $select.search = '';
};