Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Commit

Permalink
Fix incorrect dirty flag when initializing from JSON #151
Browse files Browse the repository at this point in the history
  • Loading branch information
MilosMosovsky committed May 21, 2014
1 parent a196dc3 commit 8ceb7bd
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec
$timeout(function () {
elm.select2('val', controller.$viewValue);
// Refresh angular to remove the superfluous option
elm.trigger('change');
controller.$render();
if(newVal && !oldVal && controller.$setPristine) {
controller.$setPristine(true);
}
Expand Down Expand Up @@ -206,13 +206,14 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec

// Not sure if I should just check for !isSelect OR if I should check for 'tags' key
if (!opts.initSelection && !isSelect) {
var isPristine = controller.$pristine;
controller.$setViewValue(
convertToAngularModel(elm.select2('data'))
);
if (isPristine) {
controller.$setPristine();
}
var isPristine = controller.$pristine;
controller.$pristine = false;
controller.$setViewValue(
convertToAngularModel(elm.select2('data'))
);
if (isPristine) {
controller.$setPristine();
}
elm.prev().toggleClass('ng-pristine', controller.$pristine);
}
});
Expand Down

0 comments on commit 8ceb7bd

Please sign in to comment.