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

"track by" in simple comprehension expression broke when updating from 0.11.2 to 0.13.1 #1233

Closed
mtr opened this issue Oct 5, 2015 · 15 comments · Fixed by #1477
Closed

"track by" in simple comprehension expression broke when updating from 0.11.2 to 0.13.1 #1233

mtr opened this issue Oct 5, 2015 · 15 comments · Fixed by #1477

Comments

@mtr
Copy link

mtr commented Oct 5, 2015

The expressions

<ui-select-choices
      repeat="question in questions track by question.question_id"
      group-by="'searchGroup'"
      refresh="refreshQuestions($select.search)"
      refresh-delay="250">
    <div question-preview-item="question"></div>
  </ui-select-choices>

used to work in 0.11.2, but after I upgraded to 0.13.1, I receive the following error:

Error: [$parse:syntax] Syntax Error: Token 'track' is an unexpected token at column 11 of the expression [questions track by question.question_id] starting at [track by question.question_id]

Changing the repeat value to repeat="question in questions" avoids the error message, but is probably taking a toll in reduced performance.

@dangoodman
Copy link

Same true to me. Adding a filter fixes the issue:

<ui-select-choices
    repeat="question in questions | filter: $select.search track by question.question_id"
    ....
</ui-select-choices>

@mtr
Copy link
Author

mtr commented Oct 7, 2015

As much as I appreciate your workaround, @dangoodman, it doesn't fix the issue. 😉

I really hope this issue will be properly fixed in the future, as adding a filter does not make much sense in my case where the list of questions is updated, and filtered, through an async (AJAX) server call.

@dangoodman
Copy link

Sure, it's just a workaround, not a real fix.

@alonn24
Copy link

alonn24 commented Oct 11, 2015

Happens to me also, but when updating from 0.13.1 to 0.13.2.

<ui-select-choices repeat="product in dropdownVM.productsForDropDown track by product.id"
  refresh="dropdownVM.searchProducts($select.search)"
  refresh-delay="0">

@alanbem
Copy link

alanbem commented Oct 15, 2015

This looks smelly

@rgiosa
Copy link

rgiosa commented Oct 17, 2015

+1
Downgraded from 0.13.2 to 0.13.1 and it works.

@sktwong
Copy link

sktwong commented Oct 21, 2015

@rgiosa, thank you!! Downgrading from 0.13.2 to 0.13.1 worked for me as well.

@fabn
Copy link

fabn commented Dec 2, 2015

0.13.1 didn't work for me.

@eyscode
Copy link

eyscode commented Jan 22, 2016

0.13.1 didn't work for me neither. Any solution?

@spadou
Copy link

spadou commented Jan 29, 2016

I got this issue too and need to downgrade to 0.13.0 for it to work.
It seem to be #1216 change in 0.13.1 that cause this regression.

The part that handle the filter block in the regexp for repeatFilter may be the cause. There is a | character that isn't escaped but we actually want to match the char, and this filter block should probably be optional also.

@yvesmh
Copy link

yvesmh commented Jan 30, 2016

This issue also affects custom filters:

<ui-select-choices
      repeat="result in results       
       | customFilter:$select.search
       | orderBy: result.score track by: result.result       
      ">

Throws the same error

@techniq
Copy link

techniq commented Feb 9, 2016

A workaround I found from #1270 was to wrap the collection in parens:

<ui-select-choices repeat="user in (ctrl.users) track by $index" ...>

@vicky-gonsalves
Copy link

@techniq +1

@jfairley
Copy link

jfairley commented Mar 4, 2016

@techniq 👍
this worked for me using angular 1.5 and ui-select 0.14.9

user378230 pushed a commit to user378230/ui-select that referenced this issue Mar 6, 2016
Previously the parser always attempted to extract a filter from the repeat
expression, regardless of whether it was present or not. This resulted in
the track by part of the expression being interpreted as a filter.

This commit changes the parser regex to capture the entire object source,
including its filters, before matching any track by expression. The filters
are then extracted separately from the source as this step is only required
when using an object as a source.

Fixes angular-ui#1233
@tomascharad
Copy link

Thanks @jfairley, it worked for me as well.
Just to note that I used the 0.14.9 version that is posted here: https://cdnjs.com/libraries/angular-ui-select

And I think that the version is not properly stated: Version: 0.14.8 - 2016-02-18T22:01:43.792Z
Where it should read 0.14.9

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

Successfully merging a pull request may close this issue.