Skip to content

Commit 5e5d756

Browse files
author
Florence Foo
committed
angular-ui#289 - Multiple select to not set form to dirty as soon as it load
1 parent 93434e1 commit 5e5d756

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/select.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,8 +1109,12 @@
11091109
if (oldValue != newValue)
11101110
ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters
11111111
});
1112+
$select.firstPass = true; // so the form doesn't get dirty as soon as it loads
11121113
scope.$watchCollection('$select.selected', function() {
1113-
ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes
1114+
if (!$select.firstPass)
1115+
ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes
1116+
else
1117+
$select.firstPass = false;
11141118
});
11151119
focusser.prop('disabled', true); //Focusser isn't needed if multiple
11161120
}else{

test/select.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ describe('ui-select tests', function() {
404404
beforeEach(function() {
405405
disablePerson({
406406
disableAttr : 'inactive',
407-
disableBool : true,
407+
disableBool : true
408408
});
409409
this.el = createUiSelect({
410410
disabled: 'person.inactive'
@@ -437,7 +437,7 @@ describe('ui-select tests', function() {
437437
beforeEach(function() {
438438
disablePerson({
439439
disableAttr : 'active',
440-
disableBool : false,
440+
disableBool : false
441441
});
442442
this.el = createUiSelect({
443443
disabled: '!person.active'
@@ -1123,13 +1123,13 @@ describe('ui-select tests', function() {
11231123
expect(el.find('.ui-select-match-item').length).toBe(0);
11241124
});
11251125

1126-
it('should set model as an empty array if ngModel isnt defined', function () {
1126+
it('should set model as an empty array if ngModel isnt defined after an item is selected', function () {
11271127

11281128
// scope.selection.selectedMultiple = [];
11291129
var el = createUiSelectMultiple();
1130-
1130+
expect(scope.selection.selectedMultiple instanceof Array).toBe(false);
1131+
clickItem(el, 'Samantha');
11311132
expect(scope.selection.selectedMultiple instanceof Array).toBe(true);
1132-
11331133
});
11341134

11351135
it('should render initial selected items', function() {

0 commit comments

Comments
 (0)