Skip to content

Commit f81cbc8

Browse files
committed
Merge pull request angular-ui#215 from MilosMosovsky/fix-dirty-flag
Fix incorrect dirty flag when initializing from JSON angular-ui#151
2 parents 2781639 + 4f06595 commit f81cbc8

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
@@ -139,7 +139,7 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec
139139
$timeout(function () {
140140
elm.select2('val', controller.$viewValue);
141141
// Refresh angular to remove the superfluous option
142-
elm.trigger('change');
142+
controller.$render();
143143
if(newVal && !oldVal && controller.$setPristine) {
144144
controller.$setPristine(true);
145145
}
@@ -221,13 +221,14 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec
221221

222222
// Not sure if I should just check for !isSelect OR if I should check for 'tags' key
223223
if (!opts.initSelection && !isSelect) {
224-
var isPristine = controller.$pristine;
225-
controller.$setViewValue(
226-
convertToAngularModel(elm.select2('data'))
227-
);
228-
if (isPristine) {
229-
controller.$setPristine();
230-
}
224+
var isPristine = controller.$pristine;
225+
controller.$pristine = false;
226+
controller.$setViewValue(
227+
convertToAngularModel(elm.select2('data'))
228+
);
229+
if (isPristine) {
230+
controller.$setPristine();
231+
}
231232
elm.prev().toggleClass('ng-pristine', controller.$pristine);
232233
}
233234
});

0 commit comments

Comments
 (0)