Skip to content

Commit afbdac8

Browse files
committed
feat(search box): add initSearchValue
Set the search box's text to initSearchValue instead of empty string when the dropdown gets toggled. Closes angular-ui#332
1 parent 010a373 commit afbdac8

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/uiSelectController.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ uis.controller('uiSelectCtrl',
1818
ctrl.refreshDelay = uiSelectConfig.refreshDelay;
1919
ctrl.paste = uiSelectConfig.paste;
2020

21+
ctrl.initSearchValue = EMPTY_SEARCH;
2122
ctrl.removeSelected = uiSelectConfig.removeSelected; //If selected item(s) should be removed from dropdown list
2223
ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function
2324
ctrl.skipFocusser = false; //Set to true to avoid returning focus to ctrl when item is selected
@@ -109,6 +110,7 @@ uis.controller('uiSelectCtrl',
109110
// When the user clicks on ui-select, displays the dropdown list
110111
ctrl.activate = function(initSearchValue, avoidReset) {
111112
if (!ctrl.disabled && !ctrl.open) {
113+
initSearchValue = initSearchValue !== undefined ? initSearchValue : ctrl.initSearchValue;
112114
if(!avoidReset) _resetSearchInput();
113115

114116
$scope.$broadcast('uis:activate');

src/uiSelectDirective.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ uis.directive('uiSelect',
9494
$select.removeSelected = removeSelected !== undefined ? removeSelected : uiSelectConfig.removeSelected;
9595
});
9696

97+
attrs.$observe('initSearchValue', function() {
98+
var initSearchValue = attrs.initSearchValue;
99+
$select.initSearchValue = initSearchValue !== undefined ? initSearchValue : '';
100+
});
101+
97102
attrs.$observe('disabled', function() {
98103
// No need to use $eval() (thanks to ng-disabled) since we already get a boolean instead of a string
99104
$select.disabled = attrs.disabled !== undefined ? attrs.disabled : false;

0 commit comments

Comments
 (0)