@@ -110,17 +110,27 @@ angular.module('ui.select', [])
110
110
ctrl . items = [ ] ;
111
111
ctrl . selected = undefined ;
112
112
ctrl . open = false ;
113
- ctrl . disabled = false ;
113
+ ctrl . disabled = undefined ; // Initialized inside uiSelect directive link function
114
+ ctrl . resetSearchInput = undefined ; // Initialized inside uiSelect directive link function
114
115
115
116
ctrl . searchInput = $element . querySelectorAll ( 'input.ui-select-search' ) ;
116
117
if ( ctrl . searchInput . length !== 1 ) {
117
118
throw uiSelectMinErr ( 'searchInput' , "Expected 1 input.ui-select-search but got '{0}'." , ctrl . searchInput . length ) ;
118
119
}
119
120
121
+ // Most of the time the user does not want to empty the search input when in typeahead mode
122
+ function _resetSearchInput ( ) {
123
+ if ( ctrl . resetSearchInput ) {
124
+ ctrl . search = EMPTY_SEARCH ;
125
+ }
126
+ }
127
+
120
128
// When the user clicks on ui-select, displays the dropdown list
121
129
ctrl . activate = function ( ) {
122
- if ( ctrl . disabled === false ) {
130
+ if ( ! ctrl . disabled ) {
131
+ _resetSearchInput ( ) ;
123
132
ctrl . open = true ;
133
+
124
134
// Give it time to appear before focus
125
135
$timeout ( function ( ) {
126
136
ctrl . searchInput [ 0 ] . focus ( ) ;
@@ -143,6 +153,11 @@ angular.module('ui.select', [])
143
153
} ) ;
144
154
} ;
145
155
156
+ /**
157
+ * Typeahead mode: lets the user refresh the collection using his own function.
158
+ *
159
+ * See Expose $select.search for external / remote filtering https://github.com/angular-ui/ui-select/pull/31
160
+ */
146
161
ctrl . refresh = function ( refreshAttr ) {
147
162
if ( refreshAttr !== undefined ) {
148
163
$timeout ( function ( ) {
@@ -160,8 +175,8 @@ angular.module('ui.select', [])
160
175
161
176
ctrl . close = function ( ) {
162
177
if ( ctrl . open ) {
178
+ _resetSearchInput ( ) ;
163
179
ctrl . open = false ;
164
- ctrl . search = EMPTY_SEARCH ;
165
180
}
166
181
} ;
167
182
@@ -219,7 +234,14 @@ angular.module('ui.select', [])
219
234
var ngModel = ctrls [ 1 ] ;
220
235
221
236
attrs . $observe ( 'disabled' , function ( ) {
222
- $select . disabled = attrs . disabled ? true : false ;
237
+ // No need to use $eval() (thanks to ng-disabled) since we already get a boolean instead of a string
238
+ $select . disabled = attrs . disabled !== undefined ? attrs . disabled : false ;
239
+ } ) ;
240
+
241
+ attrs . $observe ( 'resetSearchInput' , function ( ) {
242
+ // $eval() is needed otherwise we get a string instead of a boolean
243
+ var resetSearchInput = scope . $eval ( attrs . resetSearchInput ) ;
244
+ $select . resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true ;
223
245
} ) ;
224
246
225
247
scope . $watch ( '$select.selected' , function ( newValue , oldValue ) {
0 commit comments