Skip to content

Commit

Permalink
fix(ng:options): ng:change should be called after the new val is set
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorMinar committed Sep 3, 2011
1 parent 7f0b97e commit 3a779a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,8 @@ angularWidget('select', function(element){
}
}
if (isDefined(value) && model.get() !== value) {
onChange(scope);
model.set(value);
onChange(scope);
}
scope.$root.$apply();
} finally {
Expand Down
16 changes: 11 additions & 5 deletions test/widgetsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -900,22 +900,28 @@ describe("widget", function(){
createSelect({
name:'selected',
'ng:options':'value for value in values',
'ng:change':'count = count + 1'
'ng:change':'log = log + selected.name'
});
scope.values = [{name:'A'}, {name:'B'}];
scope.selected = scope.values[0];
scope.count = 0;
scope.log = '';
scope.$digest();
expect(scope.count).toEqual(0);
expect(scope.log).toEqual('');

select.val('1');
browserTrigger(select, 'change');
expect(scope.count).toEqual(1);
expect(scope.log).toEqual('B');
expect(scope.selected).toEqual(scope.values[1]);

// ignore change event when the model doesn't change
browserTrigger(select, 'change');
expect(scope.count).toEqual(1);
expect(scope.log).toEqual('B');
expect(scope.selected).toEqual(scope.values[1]);

select.val('0');
browserTrigger(select, 'change');
expect(scope.log).toEqual('BA');
expect(scope.selected).toEqual(scope.values[0]);
});

it('should update model on change through expression', function(){
Expand Down

1 comment on commit 3a779a4

@vojtajina
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I'm tired today, so it means nothing :-D

Please sign in to comment.