From a2eaf03392a6587ceb96028ccf87c796674e3d5d Mon Sep 17 00:00:00 2001 From: manassorn Date: Wed, 22 Nov 2017 13:56:42 +0700 Subject: [PATCH] fix updating valid and dirty statuses The array of functions in `controller.$parser` is executed before validation. That means the `controller.$valid` is incorrect. `controller.$valid` is still the old value when the function is executed. `controller.$viewChangeListeners` should be used instead of `controller.$parser`. That is because `controller.$viewChangeListeners` is executed after validation. --- src/select2.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/select2.js b/src/select2.js index c3b99ae..03d92bf 100644 --- a/src/select2.js +++ b/src/select2.js @@ -148,7 +148,7 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec } // Update valid and dirty statuses - controller.$parsers.push(function (value) { + controller.$viewChangeListeners.push(function () { var div = elm.prev(); div .toggleClass('ng-invalid', !controller.$valid) @@ -157,7 +157,6 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec .toggleClass('ng-valid-required', controller.$valid) .toggleClass('ng-dirty', controller.$dirty) .toggleClass('ng-pristine', controller.$pristine); - return value; }); if (!isSelect) {