@@ -97,8 +97,8 @@ angular.module('ui.select', [])
97
97
* put as much logic in the controller (instead of the link functions) as possible so it can be easily tested.
98
98
*/
99
99
. controller ( 'uiSelectCtrl' ,
100
- [ '$scope' , '$element' , '$timeout' , 'RepeatParser' , '$parse' , '$q' ,
101
- function ( $scope , $element , $timeout , RepeatParser , $parse , $q ) {
100
+ [ '$scope' , '$element' , '$timeout' , 'RepeatParser' , '$parse' , '$q' , 'uiSelectMinErr' ,
101
+ function ( $scope , $element , $timeout , RepeatParser , $parse , $q , uiSelectMinErr ) {
102
102
103
103
var ctrl = this ;
104
104
@@ -113,6 +113,9 @@ angular.module('ui.select', [])
113
113
ctrl . disabled = false ;
114
114
115
115
ctrl . searchInput = $element . querySelectorAll ( 'input.ui-select-search' ) ;
116
+ if ( ctrl . searchInput . length !== 1 ) {
117
+ throw uiSelectMinErr ( 'searchInput' , "Expected 1 input.ui-select-search but got '{0}'." , ctrl . searchInput . length ) ;
118
+ }
116
119
117
120
// When the user clicks on ui-select, displays the dropdown list
118
121
ctrl . activate = function ( ) {
@@ -218,7 +221,10 @@ angular.module('ui.select', [])
218
221
} ;
219
222
} ] )
220
223
221
- . directive ( 'uiSelect' , [ '$document' , 'uiSelectConfig' , function ( $document , uiSelectConfig ) {
224
+ . directive ( 'uiSelect' ,
225
+ [ '$document' , 'uiSelectConfig' , 'uiSelectMinErr' ,
226
+ function ( $document , uiSelectConfig , uiSelectMinErr ) {
227
+
222
228
return {
223
229
restrict : 'EA' ,
224
230
templateUrl : function ( tElement , tAttrs ) {
@@ -254,6 +260,9 @@ angular.module('ui.select', [])
254
260
function ensureHighlightVisible ( ) {
255
261
var container = element . querySelectorAll ( '.ui-select-choices-content' ) ;
256
262
var rows = container . querySelectorAll ( '.ui-select-choices-row' ) ;
263
+ if ( rows . length < 1 ) {
264
+ throw uiSelectMinErr ( 'rows' , "Expected multiple .ui-select-choices-row but got '{0}'." , rows . length ) ;
265
+ }
257
266
258
267
var highlighted = rows [ $select . activeIndex ] ;
259
268
var posY = highlighted . offsetTop + highlighted . clientHeight - container [ 0 ] . scrollTop ;
@@ -312,16 +321,25 @@ angular.module('ui.select', [])
312
321
var transcluded = angular . element ( '<div>' ) . append ( clone ) ;
313
322
314
323
var transcludedMatch = transcluded . querySelectorAll ( '.ui-select-match' ) ;
324
+ if ( transcludedMatch . length !== 1 ) {
325
+ throw uiSelectMinErr ( 'transcluded' , "Expected 1 .ui-select-match but got '{0}'." , transcludedMatch . length ) ;
326
+ }
315
327
element . querySelectorAll ( '.ui-select-match' ) . replaceWith ( transcludedMatch ) ;
316
328
317
329
var transcludedChoices = transcluded . querySelectorAll ( '.ui-select-choices' ) ;
330
+ if ( transcludedChoices . length !== 1 ) {
331
+ throw uiSelectMinErr ( 'transcluded' , "Expected 1 .ui-select-choices but got '{0}'." , transcludedChoices . length ) ;
332
+ }
318
333
element . querySelectorAll ( '.ui-select-choices' ) . replaceWith ( transcludedChoices ) ;
319
334
} ) ;
320
335
}
321
336
} ;
322
337
} ] )
323
338
324
- . directive ( 'choices' , [ 'uiSelectConfig' , 'RepeatParser' , function ( uiSelectConfig , RepeatParser ) {
339
+ . directive ( 'choices' ,
340
+ [ 'uiSelectConfig' , 'RepeatParser' , 'uiSelectMinErr' ,
341
+ function ( uiSelectConfig , RepeatParser , uiSelectMinErr ) {
342
+
325
343
return {
326
344
restrict : 'EA' ,
327
345
require : '^uiSelect' ,
@@ -336,10 +354,14 @@ angular.module('ui.select', [])
336
354
compile : function ( tElement , tAttrs ) {
337
355
var repeat = RepeatParser . parse ( tAttrs . repeat ) ;
338
356
339
- tElement . querySelectorAll ( '.ui-select-choices-row' )
340
- . attr ( 'ng-repeat' , RepeatParser . getNgRepeatExpression ( repeat . lhs , '$select.items' , repeat . trackByExp ) )
341
- . attr ( 'ng-mouseenter' , '$select.activeIndex = $index' )
342
- . attr ( 'ng-click' , '$select.select(' + repeat . lhs + ')' ) ;
357
+ var rows = tElement . querySelectorAll ( '.ui-select-choices-row' ) ;
358
+ if ( rows . length !== 1 ) {
359
+ throw uiSelectMinErr ( 'rows' , "Expected 1 .ui-select-choices-row but got '{0}'." , rows . length ) ;
360
+ }
361
+
362
+ rows . attr ( 'ng-repeat' , RepeatParser . getNgRepeatExpression ( repeat . lhs , '$select.items' , repeat . trackByExp ) )
363
+ . attr ( 'ng-mouseenter' , '$select.activeIndex = $index' )
364
+ . attr ( 'ng-click' , '$select.select(' + repeat . lhs + ')' ) ;
343
365
344
366
return function link ( scope , element , attrs , $select ) {
345
367
$select . parseRepeatAttr ( attrs . repeat ) ;
0 commit comments