-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[ngRepeat:dupes] Duplicates in repeater are not allowed. Broken after angular/ui/select upgrade #366
Comments
I've spent some time digging into this. I've been able to get past the <ui-select multiple='true' ng-model='user.roles' theme='bootstrap'>
<ui-select-match placeholder='Select a role...'> {{$item}} </ui-select-match>
<ui-select-choices repeat='role in roles track by $index'> {{role}} </ui-select-choices>
</ui-select> The big change here was from the simple attribute,
$select.multiple = (angular.isDefined(attrs.multiple)) ? (attrs.multiple === '') ? true : (attrs.multiple.toLowerCase() === 'true') : false; In the demo and docs, the attribute
It came down to that one small change. It might be good to either: a) update the docs / examples to make it explicit that $select.multiple = false;
if (angular.isDefined(attrs.multiple)) && attrs.multiple.toLowerCase() !== 'false') {
$select.multiple = true;
} |
Just ran into this exact problem, and the same thing - setting multiple to true - fixed it. For me, it was working fine on dev, but the bugs discussed here all showed up on production. Not 100% sure why - I'm minifiying all of my scripts so potentially something to do with that. The fix you listed should solve it regardless. Thanks for writing this out in so much detail! |
I'm getting this on a single-select, i.e., 'multiple' has not been specified. Anyone have any thoughts on getting around it? Thanks. |
Replacing ngModel.$formatters.unshift... in uiSelectMultiple directive
|
+1 |
@silentHoo this original issue is over two years old and the last update ~12 months. You're +1 here is not very helpful... Could you instead:
That'd be way more helpful to anyone trying to fix 😃 Thank you! 👍 |
still have the issue here with ui.select-0.17 a multiple with refresh, after adding some tags (often many) i ran into a duplicate |
I can also confirm: still happening on angular 1.5 and ui-select 0.17.1 |
I'm having the same issue with ui-select (version 2.1.3). The selected items are loaded via ajax, the correct selection will show up but when clicked to select another option, the already selected options are within the possible options and when selected again a dupe error is firing. I decided not to dig in the sources, instead to force refresh the directive from the script. This is the fix: <ui-select multiple="true" ng-model="x.itemsSelected" theme="bootstrap">
<ui-select-match placeholder="Select Eligibility Item...">{{$item.name + ' #' + $item.id}}</ui-select-match>
<ui-select-choices repeat="item.id as item in x.itemsAvailable | filter: $select.search track by $index" refresh="uiSelectRefreshFix($select)" refresh-delay="1000">
<div ng-bind-html="item.name + ' #' + item.id | highlight: $select.search"></div>
</ui-select-choices>
</ui-select> Controller // ui-select bugfix.
$scope.uiSelectRefreshFix = function () {
if ($scope.uiSelectFix) return;
$scope.uiSelectFix = true;
var fix = $scope.x.itemsSelected;
$scope.x.itemsSelected = [];
setTimeout(function() {
$scope.$apply(function(){
$scope.x.itemsSelected = fix;
});
}, 100)
console.log([model, query]);
} |
Use clone object |
I have what should amount to a fairly simple use of ui-select, in fact I've been running it in production for months now with a pinned version of angular-ui and angular b/c things have been a bit dicey trying to get angular-ui working with angular
1.3.2
. Well, today, I'm trying to update the dependencies and work through some of these issues, and this ui-select broke in the process. Here's output from bower on the versions:This is the error being thrown after the upgrade:
Obviously, this is a well-known error, and nicely documented, to boot...the problem is
track by
doesn't seem to resolve the issue, and besides, I'm binding to an array of strings in therepeat
, which shouldn't needtrack by
AFAIK, because it ought to just use the array index (I thought).Here's what the code looks like:
I added the
track by $index
but it seems to make no difference.The controller:
The interesting thing is if I breakpoint the error in Angular, it seems to be doing
ng-repeat
on each character of each string in the array, as opposed to each individual word in the array. This is why it throws the error, because the word 'superuser' contains twou
characters - which it considers a duplicate.I haven't the foggiest why it is behaving this way...any ideas are more than welcome.
This is the DOM HTML for this element, copied out of Chrome DevTools (after the error is thrown):
The text was updated successfully, but these errors were encountered: