ui-select icon indicating copy to clipboard operation
ui-select copied to clipboard

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

Open mtr opened this issue 11 years ago • 15 comments

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.

mtr avatar Oct 05 '15 13:10 mtr

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>

dangoodman avatar Oct 06 '15 19:10 dangoodman

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

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.

mtr avatar Oct 07 '15 23:10 mtr

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

dangoodman avatar Oct 08 '15 07:10 dangoodman

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">

alonn24 avatar Oct 11 '15 08:10 alonn24

This looks smelly

alanbem avatar Oct 15 '15 15:10 alanbem

+1 Downgraded from 0.13.2 to 0.13.1 and it works.

rgiosa avatar Oct 17 '15 14:10 rgiosa

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

sktwong avatar Oct 21 '15 20:10 sktwong

0.13.1 didn't work for me.

fabn avatar Dec 02 '15 16:12 fabn

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

eyscode avatar Jan 22 '16 18:01 eyscode

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.

spadou avatar Jan 29 '16 12:01 spadou

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

yvesmh avatar Jan 30 '16 00:01 yvesmh

A workaround I found from https://github.com/angular-ui/ui-select/issues/1270 was to wrap the collection in parens:

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

techniq avatar Feb 09 '16 18:02 techniq

@techniq +1

vicky-gonsalves avatar Feb 26 '16 06:02 vicky-gonsalves

@techniq :+1: this worked for me using angular 1.5 and ui-select 0.14.9

jfairley avatar Mar 04 '16 18:03 jfairley

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

tomascharad avatar Mar 08 '16 18:03 tomascharad