@@ -3,12 +3,13 @@ angular.module('ui.select', ['ui.keypress']).directive('uiSelect', function(){
3
3
restrict : 'E' ,
4
4
/* jshint multistr: true */
5
5
template : '<div class="select" ng-class="{open:open}"> \
6
- <input type="{{type}}" ui-keydown="{up: \'up()\', down: \'down()\'}" ng-model="$search" ng-click="activate()"> \
6
+ <input type="{{type}}" ui-keydown="{up: \'up()\', down: \'down()\', enter: \'$select((data.items|filter: $select.search)[$select.index].title)\' }" ng-model="$select. search" ng-click="activate()"> \
7
7
<ul ng-transclude></ul> \
8
8
</div>' ,
9
9
replace : true ,
10
10
require : 'ngModel' ,
11
11
transclude : true ,
12
+ // scope: true,
12
13
link : function ( $scope , $elm , $attrs , ngModel ) {
13
14
14
15
//Setting keybindings to scope wasn't working, since ui-keydown directive
@@ -22,30 +23,33 @@ angular.module('ui.select', ['ui.keypress']).directive('uiSelect', function(){
22
23
$scope . type = 'text' ;
23
24
input . focus ( ) ;
24
25
} ;
25
- $scope . $watch ( '$search' , function ( ) {
26
- $scope . highlight = 0 ;
26
+ $scope . $watch ( '$select. search' , function ( ) {
27
+ $scope . $select . index = 0 ;
27
28
} ) ;
28
29
$scope . up = function ( ) {
29
- if ( $scope . highlight > 0 )
30
- $scope . highlight -- ;
30
+ if ( $scope . $select . index > 0 )
31
+ $scope . $select . index -- ;
31
32
} ;
32
33
$scope . down = function ( ) {
33
34
items = $elm . find ( 'ul' ) . children ( ) . length ;
34
- if ( $scope . highlight < items ) {
35
- $scope . highlight ++ ;
35
+ if ( $scope . $select . index < items ) {
36
+ $scope . $select . index ++ ;
36
37
} else {
37
- $scope . highlight = items ;
38
+ $scope . $select . index = items ;
38
39
}
39
40
} ;
40
- $scope . select = function ( item ) {
41
+ $scope . $ select = function ( item ) {
41
42
ngModel . $setViewValue ( item ) ;
43
+ ngModel . $render ( item ) ;
44
+ $scope . close ( ) ;
45
+ } ;
46
+ $scope . close = function ( ) {
47
+ $scope . open = false ;
48
+ $scope . type = 'button' ;
42
49
} ;
43
50
ngModel . $render = function ( ) {
44
- $scope . $search = ngModel . $viewValue ;
51
+ $scope . $select . search = ngModel . $viewValue ;
45
52
} ;
46
- input . bind ( 'blur' , function ( ) {
47
- $scope . $apply ( 'open=false;type="button"' ) ;
48
- } ) ;
49
53
}
50
54
} ;
51
55
} ) ;
0 commit comments