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

"Track by" does not work on multiple ui-select with objects #665

Open
artkoenig opened this issue Feb 14, 2015 · 35 comments
Open

"Track by" does not work on multiple ui-select with objects #665

artkoenig opened this issue Feb 14, 2015 · 35 comments

Comments

@artkoenig
Copy link

Here the example:
http://plnkr.co/edit/3KLlmX19Qx6meOk52Jyn?p=preview

Using track by in "Array of objects" example has no effect, angular generates $$hashKey fields for selected objects.

@abobwhite
Copy link

I am also seeing this issue. It's become very problematic.

@abobwhite
Copy link

It's hard to look back to the old files because the code was recently split into new files.

@johaven
Copy link

johaven commented Apr 16, 2015

+1 :(

@nashant
Copy link

nashant commented May 3, 2015

Is there going to be a fix for this some time soon? At the moment I'm having to resort to using angular.extend() to add the $$hashKey

@thefewminutes
Copy link

+1

@estvmachine
Copy link

Exist a partial solution for this problem?? @nashant.

@evillemez
Copy link

Yeah, this one kinda hurts... track by usually helps with performance, and I have a huge list of objects (languages) in a multiselect.

@catchshyam
Copy link
Contributor

+1

2 similar comments
@williamoliveira
Copy link

+1

@arseneoaa
Copy link

+1

@nadavsinai
Copy link

+1

8 similar comments
@NetanelBasal
Copy link

+1

@morozovm
Copy link

+1

@logannc
Copy link

logannc commented Dec 3, 2015

+1

@sidoruk-sv
Copy link

+1

@nadavivry
Copy link

+1

@n3wtn9
Copy link

n3wtn9 commented Dec 21, 2015

+1

@noxan
Copy link

noxan commented Jan 7, 2016

+1

@acabra85
Copy link

+1

mlix11 added a commit to mlix11/ui-select that referenced this issue Jan 11, 2016
@mlix11
Copy link
Contributor

mlix11 commented Jan 12, 2016

I hope my fix helps

@acabra85
Copy link

I have seen the pull request, #1383, it says the CI tests failed. Thanks for your posting

@mlix11
Copy link
Contributor

mlix11 commented Jan 13, 2016

The pull request fails because of the old build workflow. Other pull requests have the same issue.

@estvmachine
Copy link

:( good try!

@giacomolm
Copy link

+1
I created a filter as a workaround, but I would prefer to use 'track by' - mainly for performance issue (I didn't understand when the filters are called). Does it work the from the latest commit?

aaronroberson added a commit that referenced this issue Feb 18, 2016
Eenhance regex functions to avoid failures with the "track by" feature

Fixes #806 and #665
@artuska
Copy link

artuska commented Mar 18, 2016

+1

@aaronroberson
Copy link
Contributor

@artuska This fix landed in 0.16.0. Please see 6c52e41 and confirm or deny.

@fmoutawe
Copy link

Still occured in v0.16.1.

<ui-select-choices repeat="purposeOfVisit in purposeOfVisits | filter: {name: $select.search} track by purposeOfVisit.id"> doesn't delete $$hashkey in object.

@fromthemills
Copy link

Also on 0.17.1 still occurring.

@dunwho
Copy link

dunwho commented Jul 25, 2016

The first response here provided a solution for me. It seems that simply including "multiple" as an attribute rather than " multiple='true' " causes validation errors within select.js.

Also, if you track by $index with the above change it seems to work fine.

Original Article

I've spent some time digging into this. I've been able to get past the ngRepeat:dupes by making the following changes:

<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, multiple to multiple="true". The logic for determining if multiple is in play seems wrong (despite being woefully hard to read...sorry)?

@fromthemills
Copy link

fromthemills commented Jul 28, 2016

Just gave it a test quick and this does indeed solve this issue...

@user378230
Copy link
Contributor

The line

$select.multiple = (angular.isDefined(attrs.multiple)) ? (attrs.multiple === '') ? true : (attrs.multiple.toLowerCase() === 'true') : false;

Doesn't exist.

$select.multiple = true

Is set in the uiSelectMultiple directive itself.

@laurenmacam
Copy link

+1

@agpt
Copy link

agpt commented Oct 27, 2016

👍 for me, I have two ui-select in my view. very strange that for one instance its working fine, but for its sibling ui-select, it is not. any fixes ?

For me it worked, when I renamed the variable and added track by in another ng-repeat in which I was using the same object array.

// $ctrl.reportConfig.filters renamed to filterType

<ui-select multiple ng-model="$ctrl.reportConfig.filterType" sortable="true" close-on-select="false" theme="bootstrap" title="Choose a Filter" on-select="$ctrl.onSelectFilter($item, $model)">
          <ui-select-match allow-clear="true" placeholder="Select a Filter in the list...">{{$item.alias}} &lt;{{$item.fieldSets.fields.alias}}&gt;</ui-select-match>
          <ui-select-choices repeat="f in $ctrl.filters | filter: $select.search track by f.x.y.alias" group-by="'alias'">
            <div ng-bind-html="f.x.y.alias | highlight: $select.search"></div>
          </ui-select-choices>
        </ui-select>

// I am using filterType array to generate another set of ui-select here

    <div class="form-group" ng-repeat="field in $ctrl.reportConfig.filterType track by field.alias"> // <= I added track by field.alias here
      <label for="" class="col-md-2 control-label"></label>
      <div class="col-md-4">
        <ui-select multiple ng-model="$ctrl.reportConfig.x[field.name]" close-on-select="false" title="Choose {{field.alias}}" on-select="$ctrl.onSelectFilterFields($item, $model)">
          <ui-select-match placeholder="Select {{field.alias}} in the list...">{{$item.name}}</ui-select-match>
          <ui-select-choices repeat="fil in $ctrl.getData(field.name) | filter: $select.search track by fil.name" group-by="'alias'"> // <= and added another track by here as well
            <div ng-bind-html="fil.name | highlight: $select.search"></div>
          </ui-select-choices>
        </ui-select>
      </div>
    </div>

@apodznoev
Copy link

@agupta-q4 Thank you man for a code! It didn't resolved the issue with a hash key but fixed my problem with filtering using track by =)

@iMomen
Copy link

iMomen commented Nov 22, 2017

+1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests