Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.
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

Description

@gerrod

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions