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

Enable tagging without multi selection (see #597) #657

Merged
merged 1 commit into from
Feb 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions examples/demo-tagging.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ <h3>Object Tags with Tokenization (Space, Forward Slash, Comma)</h3>
</ui-select>
<p>Selected: {{multipleDemo.selectedPeople2}}</p>

<h3>Tagging without multiple</h3>
<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">
<ui-select-match placeholder="Select person...">{{$select.selected.name}} &lt;{{$select.selected.email}}&gt;</ui-select-match>
<ui-select-choices repeat="person in people | propsFilter: {name: $select.search, age: $select.search}">
<div ng-if="person.isTag" ng-bind-html="person.name +' <small>(new)</small>'| highlight: $select.search"></div>
<div ng-if="!person.isTag" ng-bind-html="person.name + person.isTag| highlight: $select.search"></div>
<small>
email: {{person.email}}
age: <span ng-bind-html="''+person.age | highlight: $select.search"></span>
</small>
</ui-select-choices>
</ui-select>
<p>Selected: {{person.selected}}</p>


<div style="height:500px"></div>

</body>
Expand Down
7 changes: 7 additions & 0 deletions examples/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
Expand Down
38 changes: 20 additions & 18 deletions src/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -818,24 +818,26 @@
}

function _findApproxDupe(haystack, needle) {
var tempArr = angular.copy(haystack);
var dupeIndex = -1;
for (var i = 0; i <tempArr.length; i++) {
// handle the simple string version of tagging
if ( ctrl.tagging.fct === undefined ) {
// search the array for the match
if ( tempArr[i]+' '+ctrl.taggingLabel === needle ) {
dupeIndex = i;
}
// handle the object tagging implementation
} else {
var mockObj = tempArr[i];
mockObj.isTag = true;
if ( angular.equals(mockObj, needle) ) {
dupeIndex = i;
}
}
}
if(angular.isArray(haystack)) {
var tempArr = angular.copy(haystack);
for (var i = 0; i <tempArr.length; i++) {
// handle the simple string version of tagging
if ( ctrl.tagging.fct === undefined ) {
// search the array for the match
if ( tempArr[i]+' '+ctrl.taggingLabel === needle ) {
dupeIndex = i;
}
// handle the object tagging implementation
} else {
var mockObj = tempArr[i];
mockObj.isTag = true;
if ( angular.equals(mockObj, needle) ) {
dupeIndex = i;
}
}
}
}
return dupeIndex;
}

Expand Down