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

Commit 0af1915

Browse files
committed
Enable tagging without multi selection
1 parent 4da2db4 commit 0af1915

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
lines changed

Diff for: examples/demo-tagging.html

+15
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ <h3>Object Tags with Tokenization (Space, Forward Slash, Comma)</h3>
116116
</ui-select>
117117
<p>Selected: {{multipleDemo.selectedPeople2}}</p>
118118

119+
<h3>Tagging without multiple</h3>
120+
<ui-select tagging="tagTransform" ng-model="person.selected" on-select="addPerson($item, $model)" theme="bootstrap" ng-disabled="disabled" style="width: 800px;" title="Choose a person">
121+
<ui-select-match placeholder="Select person...">{{$select.selected.name}} &lt;{{$select.selected.email}}&gt;</ui-select-match>
122+
<ui-select-choices repeat="person in people | propsFilter: {name: $select.search, age: $select.search}">
123+
<div ng-if="person.isTag" ng-bind-html="person.name +' <small>(new)</small>'| highlight: $select.search"></div>
124+
<div ng-if="!person.isTag" ng-bind-html="person.name + person.isTag| highlight: $select.search"></div>
125+
<small>
126+
email: {{person.email}}
127+
age: <span ng-bind-html="''+person.age | highlight: $select.search"></span>
128+
</small>
129+
</ui-select-choices>
130+
</ui-select>
131+
<p>Selected: {{person.selected}}</p>
132+
133+
119134
<div style="height:500px"></div>
120135

121136
</body>

Diff for: examples/demo.js

+7
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ app.controller('DemoCtrl', function($scope, $http, $timeout) {
153153
});
154154
};
155155

156+
$scope.addPerson = function(item, model){
157+
if(item.hasOwnProperty('isTag')) {
158+
delete item.isTag;
159+
$scope.people.push(item);
160+
}
161+
}
162+
156163
$scope.country = {};
157164
$scope.countries = [ // Taken from https://gist.github.com/unceus/6501985
158165
{name: 'Afghanistan', code: 'AF'},

Diff for: src/select.js

+20-18
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@
420420
}
421421
}
422422
// search ctrl.selected for dupes potentially caused by tagging and return early if found
423-
if ( ctrl.selected && ctrl.selected.filter( function (selection) { return angular.equals(selection, item); }).length > 0 ) {
423+
if ( ctrl.selected && angular.isArray(ctrl.selected) && ctrl.selected.filter( function (selection) { return angular.equals(selection, item); }).length > 0 ) {
424424
ctrl.close(skipFocusser);
425425
return;
426426
}
@@ -818,24 +818,26 @@
818818
}
819819

820820
function _findApproxDupe(haystack, needle) {
821-
var tempArr = angular.copy(haystack);
822821
var dupeIndex = -1;
823-
for (var i = 0; i <tempArr.length; i++) {
824-
// handle the simple string version of tagging
825-
if ( ctrl.tagging.fct === undefined ) {
826-
// search the array for the match
827-
if ( tempArr[i]+' '+ctrl.taggingLabel === needle ) {
828-
dupeIndex = i;
829-
}
830-
// handle the object tagging implementation
831-
} else {
832-
var mockObj = tempArr[i];
833-
mockObj.isTag = true;
834-
if ( angular.equals(mockObj, needle) ) {
835-
dupeIndex = i;
836-
}
837-
}
838-
}
822+
if(angular.isArray(haystack)) {
823+
var tempArr = angular.copy(haystack);
824+
for (var i = 0; i <tempArr.length; i++) {
825+
// handle the simple string version of tagging
826+
if ( ctrl.tagging.fct === undefined ) {
827+
// search the array for the match
828+
if ( tempArr[i]+' '+ctrl.taggingLabel === needle ) {
829+
dupeIndex = i;
830+
}
831+
// handle the object tagging implementation
832+
} else {
833+
var mockObj = tempArr[i];
834+
mockObj.isTag = true;
835+
if ( angular.equals(mockObj, needle) ) {
836+
dupeIndex = i;
837+
}
838+
}
839+
}
840+
}
839841
return dupeIndex;
840842
}
841843

0 commit comments

Comments
 (0)