angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

ng-option does not update model when filtered

Open caiotoon opened this issue 13 years ago • 1 comments

When the previously selected value is filtered out the select, ng-model doesn't update to null. This behavior was spotted in this StackOverflow question.

Basically, this (mocked) test should fail:

it('should update ng-model if previous value is no more', function() {
  createSelect({
    'ng-model': 'selected',
    'ng-options': 'value for value in values | filter: filterValues'
  }, true);

  scope.values = ['red', 'green', 'blue'];
  scope.filterValues = function() {
    return !scope.blockAll;
  };

  scope.$digest();
  expect(scope.selected).toBeUndefined();
  angular.element(element.find('option')[1]).attr('selected', 'selected');
  element.triggerHandler('change');
  scope.$digest();
  expect(scope.selected).toBe('red');

  scope.blockAll = true;
  scope.$digest();
  expect(scope.selected).toBeUndefined();
});

The following fail would happen in the last line: "Expected 'red' to be undefined."

For those not familiarized with selectSpecs, the createSelect creates and compile a select with the attributes informed, and expose its scope through scope variable.

caiotoon avatar Mar 20 '13 13:03 caiotoon

As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months.

Please try the newest versions of Angular (1.0.8 and 1.2.0-rc.1), and if the issue persists, comment below so we can discuss it.

Thanks!

btford avatar Aug 24 '13 00:08 btford