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

Add attr (tagging-equals) to set a property for equality in custom objects (tagging) #1939

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion src/uiSelectDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ uis.directive('uiSelect',
}
});

attrs.$observe('taggingEquals', function() {
if (attrs.tagging !== undefined) {
// Used for check token equality by single property with custom objects
var property = attrs.taggingEquals !== undefined ? attrs.taggingEquals : undefined;
$select.taggingEqualsProperty = property;
}
});

attrs.$observe('spinnerEnabled', function() {
// $eval() is needed otherwise we get a string instead of a boolean
var spinnerEnabled = scope.$eval(attrs.spinnerEnabled);
Expand Down Expand Up @@ -378,7 +386,7 @@ uis.directive('uiSelect',
};

var opened = false;

scope.calculateDropdownPos = function() {
if ($select.open) {
dropdown = angular.element(element).querySelectorAll('.ui-select-dropdown');
Expand Down
20 changes: 14 additions & 6 deletions src/uiSelectMultipleDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
return;
}
$select.selected.push(item);
var locals = {};
var locals = {};
locals[$select.parserResult.itemName] = item;

$timeout(function(){
Expand Down Expand Up @@ -261,11 +261,11 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
} else {
return curr;
}

} else {
// If nothing yet selected, select last item
return last;
}
return last;
}
break;
case KEY.DELETE:
// Remove selected item and select next item
Expand Down Expand Up @@ -329,10 +329,18 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
// verify the new tag doesn't match the value of a possible selection choice or an already selected item.
if (
stashArr.some(function (origItem) {
return angular.equals(origItem, newItem);
if($select.taggingEqualsProperty){
return angular.equals(origItem[$select.taggingEqualsProperty], newItem[$select.taggingEqualsProperty]);
} else {
return angular.equals(origItem, newItem);
}
}) ||
$select.selected.some(function (origItem) {
return angular.equals(origItem, newItem);
if($select.taggingEqualsProperty){
return angular.equals(origItem[$select.taggingEqualsProperty], newItem[$select.taggingEqualsProperty]);
} else {
return angular.equals(origItem, newItem);
}
})
) {
scope.$evalAsync(function () {
Expand Down