Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit aeb9649

Browse files
author
Brian Feister
committed
Improve modularity and fix issue mentioned at #327 (comment)
1 parent 90b7b14 commit aeb9649

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/select.js

+18-4
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@
615615
if ( ctrl.taggingTokens.tokens[i] === KEY.MAP[e.keyCode] ) {
616616
// make sure there is a new value to push via tagging
617617
if ( ctrl.search.length > 0 ) {
618-
ctrl.select(null, true);
618+
ctrl.select(undefined, true);
619619
_searchInput.triggerHandler('tagged');
620620
}
621621
}
@@ -704,7 +704,7 @@
704704
}
705705
// verify the the tag doesn't match the value of an existing item from
706706
// the searched data set
707-
if ( stashArr.filter( function (origItem) { return origItem.toUpperCase() === ctrl.search.toUpperCase(); }).length > 0 ) {
707+
if ( _findCaseInsensitiveDupe(stashArr) ) {
708708
// if there is a tag from prev iteration, strip it / queue the change
709709
// and return early
710710
if ( hasTag ) {
@@ -716,7 +716,7 @@
716716
}
717717
return;
718718
}
719-
if ( ctrl.selected.filter( function (selection) { return selection.toUpperCase() === ctrl.search.toUpperCase(); } ).length > 0 ) {
719+
if ( _findCaseInsensitiveDupe(stashArr) ) {
720720
// if there is a tag from prev iteration, strip it
721721
if ( hasTag ) {
722722
ctrl.items = stashArr.slice(1,stashArr.length);
@@ -752,6 +752,20 @@
752752
});
753753
});
754754

755+
function _findCaseInsensitiveDupe(arr) {
756+
if ( arr === undefined || ctrl.search === undefined ) {
757+
return false;
758+
}
759+
var hasDupe = arr.filter( function (origItem) {
760+
if ( ctrl.search.toUpperCase() === undefined ) {
761+
return false;
762+
}
763+
return origItem.toUpperCase() === ctrl.search.toUpperCase();
764+
}).length > 0;
765+
766+
return hasDupe;
767+
}
768+
755769
function _findApproxDupe(haystack, needle) {
756770
var tempArr = angular.copy(haystack);
757771
var dupeIndex = -1;
@@ -1220,7 +1234,7 @@
12201234
attrs.$observe('placeholder', function(placeholder) {
12211235
$select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder;
12221236
});
1223-
1237+
12241238
$select.allowClear = (angular.isDefined(attrs.allowClear)) ? (attrs.allowClear === '') ? true : (attrs.allowClear.toLowerCase() === 'true') : false;
12251239

12261240
if($select.multiple){

0 commit comments

Comments
 (0)