From 0af1915ce951eeb13dd1342bc55658932acc9f39 Mon Sep 17 00:00:00 2001 From: catchshyam Date: Thu, 12 Feb 2015 21:57:50 +0530 Subject: [PATCH] Enable tagging without multi selection --- examples/demo-tagging.html | 15 +++++++++++++++ examples/demo.js | 7 +++++++ src/select.js | 38 ++++++++++++++++++++------------------ 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/examples/demo-tagging.html b/examples/demo-tagging.html index b2cc6cf7a..fa732f920 100644 --- a/examples/demo-tagging.html +++ b/examples/demo-tagging.html @@ -116,6 +116,21 @@

Object Tags with Tokenization (Space, Forward Slash, Comma)

Selected: {{multipleDemo.selectedPeople2}}

+

Tagging without multiple

+ + {{$select.selected.name}} <{{$select.selected.email}}> + +
+
+ + email: {{person.email}} + age: + +
+
+

Selected: {{person.selected}}

+ +
diff --git a/examples/demo.js b/examples/demo.js index 96fe294fb..6fa140346 100644 --- a/examples/demo.js +++ b/examples/demo.js @@ -153,6 +153,13 @@ app.controller('DemoCtrl', function($scope, $http, $timeout) { }); }; + $scope.addPerson = function(item, model){ + if(item.hasOwnProperty('isTag')) { + delete item.isTag; + $scope.people.push(item); + } + } + $scope.country = {}; $scope.countries = [ // Taken from https://gist.github.com/unceus/6501985 {name: 'Afghanistan', code: 'AF'}, diff --git a/src/select.js b/src/select.js index f8906c235..edfeb8458 100644 --- a/src/select.js +++ b/src/select.js @@ -420,7 +420,7 @@ } } // search ctrl.selected for dupes potentially caused by tagging and return early if found - if ( ctrl.selected && ctrl.selected.filter( function (selection) { return angular.equals(selection, item); }).length > 0 ) { + if ( ctrl.selected && angular.isArray(ctrl.selected) && ctrl.selected.filter( function (selection) { return angular.equals(selection, item); }).length > 0 ) { ctrl.close(skipFocusser); return; } @@ -818,24 +818,26 @@ } function _findApproxDupe(haystack, needle) { - var tempArr = angular.copy(haystack); var dupeIndex = -1; - for (var i = 0; i