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

Duplicates in a repeater bug introduced in 0.9.8 #695

Closed
gerrod opened this issue Feb 24, 2015 · 5 comments
Closed

Duplicates in a repeater bug introduced in 0.9.8 #695

gerrod opened this issue Feb 24, 2015 · 5 comments

Comments

@gerrod
Copy link

gerrod commented Feb 24, 2015

Hi guys -

I've recently upgraded ui-select from 0.9.6 to 0.9.9 and encountered the infamous "Duplicates in a repeater are not allowed" bug.

The bug only shows up if the ui-select is populated after the control is compiled - for example, if you're loading the values to bind from a server call. I've reproduced the problem here. In the script.js file you can change the value of SIMULATE_LOAD to false and you'll see the problem goes away, but when set as true and we're simulating a load from the server, you get the duplicates bug.

The bug was introduced in 0.9.8 in the following block of code:

var checkFnMultiple = function(list, value){
  //if the list is empty add the value to the list
  /***************************************************************/
  /* THIS IS THE CODE THAT INTRODUCED THE BUG                    */
  /***************************************************************/
  if (!list || !list.length){
      resultMultiple.unshift(value);
      return true;
  }

  // Previously the code was:
  // if (!list || !list.length) return;
  /***************************************************************/
  for (var p = list.length - 1; p >= 0; p--) {
    locals[$select.parserResult.itemName] = list[p];
    result = $select.parserResult.modelMapper(scope, locals);
    if($select.parserResult.trackByExp){
        var matches = /\.(.+)/.exec($select.parserResult.trackByExp);
        if(matches.length>0 && result[matches[1]] == value[matches[1]]){
            resultMultiple.unshift(list[p]);
            return true;
        }
    }
    if (result == value){
      resultMultiple.unshift(list[p]);
      return true;
    }
  }
  return false;
};

Hope that helps!

@sofiageo
Copy link

Thanks for this, I had no idea when this bug was introduced, so I was trying to patch this bug for my build. Reverting back to 0.9.7 seems to fix this problem!

@drewfreyling
Copy link

Hoping this gets fixed soon.

@sofiageo
Copy link

@drewfreyling I think they are already looking into it in this issue: #748

@drewfreyling
Copy link

Looks like 0.11.2 fixes this.

@gerrod
Copy link
Author

gerrod commented Mar 24, 2015

Sweet!

@gerrod gerrod closed this as completed Mar 24, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants