Skip to content

Commit fc93c66

Browse files
author
Brian Feister
committed
1 parent 7c9dfc1 commit fc93c66

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

examples/demo-tagging.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
</script>
1919
<![endif]-->
2020

21-
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular.js"></script>
22-
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular-sanitize.js"></script>
21+
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.js"></script>
22+
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular-sanitize.js"></script>
2323
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.css">
2424

2525
<!-- ui-select files -->
@@ -106,7 +106,7 @@ <h3>Object Tags with Tokenization (Space, Forward Slash, Comma)</h3>
106106
<ui-select multiple tagging="tagTransform" tagging-tokens="SPACE|,|/" ng-model="multipleDemo.selectedPeople2" theme="bootstrap" ng-disabled="disabled" style="width: 800px;">
107107
<ui-select-match placeholder="Select person...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match>
108108
<ui-select-choices repeat="person in people | propsFilter: {name: $select.search, age: $select.search}">
109-
<div ng-if="person.isTag" ng-bind-html="person.name +' <small>(new)</small>'| highlight: $select.search"></div>
109+
<div ng-if="person.isTag" ng-bind-html="person.name + ' ' + $select.taggingLabel | highlight: $select.search"></div>
110110
<div ng-if="!person.isTag" ng-bind-html="person.name| highlight: $select.search"></div>
111111
<small>
112112
email: {{person.email}}

examples/demo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ app.controller('DemoCtrl', function($scope, $http, $timeout) {
109109
$scope.tagTransform = function (newTag) {
110110
var item = {
111111
name: newTag,
112-
email: newTag+'@email.com',
112+
email: newTag.toLowerCase()+'@email.com',
113113
age: 'unknown',
114114
country: 'unknown'
115115
};

src/select.js

+20-12
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
DELETE: 46,
2222
COMMAND: 91,
2323

24-
MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "SPACE" , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'"
24+
MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "," , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'"
2525
},
2626

2727
isControl: function (e) {
@@ -398,17 +398,18 @@
398398
var locals = {};
399399
locals[ctrl.parserResult.itemName] = item;
400400

401-
ctrl.onSelectCallback($scope, {
402-
$item: item,
403-
$model: ctrl.parserResult.modelMapper($scope, locals)
404-
});
405-
406401
if(ctrl.multiple) {
407402
ctrl.selected.push(item);
408403
ctrl.sizeSearchInput();
409404
} else {
410405
ctrl.selected = item;
411406
}
407+
408+
ctrl.onSelectCallback($scope, {
409+
$item: item,
410+
$model: ctrl.parserResult.modelMapper($scope, locals)
411+
});
412+
412413
if (!ctrl.multiple || ctrl.closeOnSelect) {
413414
ctrl.close(skipFocusser);
414415
}
@@ -615,8 +616,14 @@
615616
if ( ctrl.taggingTokens.tokens[i] === KEY.MAP[e.keyCode] ) {
616617
// make sure there is a new value to push via tagging
617618
if ( ctrl.search.length > 0 ) {
618-
ctrl.select(undefined, true);
619-
_searchInput.triggerHandler('tagged');
619+
$timeout(function() {
620+
_searchInput.triggerHandler('tagged', ctrl.items);
621+
var newItem = ctrl.search.replace(KEY.MAP[e.keyCode],'').trim();
622+
if ( ctrl.tagging.fct ) {
623+
newItem = ctrl.tagging.fct( newItem );
624+
}
625+
ctrl.select( newItem, true);
626+
});
620627
}
621628
}
622629
}
@@ -655,7 +662,7 @@
655662
// taggingLabel === false bypasses all of this
656663
if (ctrl.taggingLabel === false) return;
657664

658-
var items = angular.copy( ctrl.items );
665+
var items = angular.copy( ctrl.items )
659666
var stashArr = angular.copy( ctrl.items );
660667
var newItem;
661668
var item;
@@ -703,8 +710,8 @@
703710
return;
704711
}
705712
// verify the the tag doesn't match the value of an existing item from
706-
// the searched data set
707-
if ( _findCaseInsensitiveDupe(stashArr) ) {
713+
// the searched data set or the items already selected
714+
if ( _findCaseInsensitiveDupe(stashArr.concat(ctrl.selected)) ) {
708715
// if there is a tag from prev iteration, strip it / queue the change
709716
// and return early
710717
if ( hasTag ) {
@@ -1036,7 +1043,7 @@
10361043
});
10371044

10381045
attrs.$observe('taggingLabel', function() {
1039-
if(attrs.tagging !== undefined && attrs.taggingLabel !== undefined)
1046+
if(attrs.tagging !== undefined )
10401047
{
10411048
// check eval for FALSE, in this case, we disable the labels
10421049
// associated with tagging
@@ -1261,3 +1268,4 @@
12611268
};
12621269
});
12631270
}());
1271+

0 commit comments

Comments
 (0)