diff options
| author | Misko Hevery | 2011-07-14 13:54:34 -0700 | 
|---|---|---|
| committer | Misko Hevery | 2011-07-26 09:41:44 -0700 | 
| commit | 3237f8b9950ab0dbf3c80f6bef40217ea7cf96ae (patch) | |
| tree | c04e4c6ae97a2e6fbfd4b9e47c7ba993c3561afc | |
| parent | 7802c90e139a36d37b9d3c8cd6b6fcfee042dd71 (diff) | |
| download | angular.js-3237f8b9950ab0dbf3c80f6bef40217ea7cf96ae.tar.bz2 | |
fix(directive): ng:options to support ng:change
Closes #463
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | src/widgets.js | 6 | ||||
| -rw-r--r-- | test/widgetsSpec.js | 21 | 
3 files changed, 27 insertions, 1 deletions
| diff --git a/CHANGELOG.md b/CHANGELOG.md index c3b9251b..2ef1b35d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@  - Issue #449: [ng:options] should support binding to a property of an item.  - Issue #464: [ng:options] incorrectly re-grew options on datasource change  - Issue #448: [ng:options] should support iterating over objects +- Issue #463: [ng:options] should support firing ng:change event  ### Breaking changes  - no longer support MMMMM in filter.date as we need to follow UNICODE LOCALE DATA formats. diff --git a/src/widgets.js b/src/widgets.js index bdd68804..17a14741 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -674,6 +674,7 @@ angularWidget('select', function(element){    this.directives(true);    var isMultiselect = element.attr('multiple');    var expression = element.attr('ng:options'); +  var onChange = expressionCompile(element.attr('ng:change') || "").fnSelf;    var match;    if (!expression) {      return inputWidgetSelector.call(this, element); @@ -729,7 +730,10 @@ angularWidget('select', function(element){              value = valueFn(tempScope);            }          } -        if (!isUndefined(value)) model.set(value); +        if (!isUndefined(value) && model.get() !== value) { +          onChange(scope); +          model.set(value); +        }          scope.$tryEval(function(){            scope.$root.$eval();          }); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 422ca86b..e2a070c4 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -859,6 +859,27 @@ describe("widget", function(){          expect(scope.selected).toEqual(scope.values[1]);        }); +      it('should fire ng:change if present', function(){ +        createSelect({ +          name:'selected', +          'ng:options':'value for value in values', +          'ng:change':'count = count + 1'}); +        scope.values = [{name:'A'}, {name:'B'}]; +        scope.selected = scope.values[0]; +        scope.count = 0; +        scope.$eval(); +        expect(scope.count).toEqual(0); + +        select.val('1'); +        browserTrigger(select, 'change'); +        expect(scope.count).toEqual(1); +        expect(scope.selected).toEqual(scope.values[1]); + +        browserTrigger(select, 'change'); +        expect(scope.count).toEqual(1); +        expect(scope.selected).toEqual(scope.values[1]); +      }); +        it('should update model on change through expression', function(){          createSelect({name:'selected', 'ng:options':'item.id as item.name for item in values'});          scope.values = [{id:10, name:'A'}, {id:20, name:'B'}]; | 
