Skip to content

Commit 8ceb7bd

Browse files
committed
Fix incorrect dirty flag when initializing from JSON angular-ui#151
1 parent a196dc3 commit 8ceb7bd

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/select2.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec
124124
$timeout(function () {
125125
elm.select2('val', controller.$viewValue);
126126
// Refresh angular to remove the superfluous option
127-
elm.trigger('change');
127+
controller.$render();
128128
if(newVal && !oldVal && controller.$setPristine) {
129129
controller.$setPristine(true);
130130
}
@@ -206,13 +206,14 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec
206206

207207
// Not sure if I should just check for !isSelect OR if I should check for 'tags' key
208208
if (!opts.initSelection && !isSelect) {
209-
var isPristine = controller.$pristine;
210-
controller.$setViewValue(
211-
convertToAngularModel(elm.select2('data'))
212-
);
213-
if (isPristine) {
214-
controller.$setPristine();
215-
}
209+
var isPristine = controller.$pristine;
210+
controller.$pristine = false;
211+
controller.$setViewValue(
212+
convertToAngularModel(elm.select2('data'))
213+
);
214+
if (isPristine) {
215+
controller.$setPristine();
216+
}
216217
elm.prev().toggleClass('ng-pristine', controller.$pristine);
217218
}
218219
});

0 commit comments

Comments
 (0)