From 5d4ed464e4d786f485ea7ff7eeddc80f154f169a Mon Sep 17 00:00:00 2001 From: Shahar Talmi Date: Sat, 30 Aug 2014 04:07:14 +0300 Subject: [PATCH] refactor(ngModel): get rid of revalidate --- src/ng/directive/input.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index abc689193ee7..3834298c373c 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -914,7 +914,6 @@ function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) { var validity = element.prop(VALIDITY_STATE_PROPERTY); var placeholder = element[0].placeholder, noevent = {}; var type = lowercase(element[0].type); - ctrl.$$validityState = validity; // In composition mode, users are still inputing intermediate text buffer, // hold the listener until composition is done. @@ -956,13 +955,12 @@ function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) { // If a control is suffering from bad input, browsers discard its value, so it may be // necessary to revalidate even if the control's value is the same empty value twice in // a row. - var revalidate = validity && ctrl.$$hasNativeValidators; - if (ctrl.$viewValue !== value || (value === '' && revalidate)) { + if (ctrl.$viewValue !== value || (value === '' && ctrl.$$hasNativeValidators)) { if (scope.$root.$$phase) { - ctrl.$setViewValue(value, event, revalidate); + ctrl.$setViewValue(value, event); } else { scope.$apply(function() { - ctrl.$setViewValue(value, event, revalidate); + ctrl.$setViewValue(value, event); }); } } @@ -1980,11 +1978,11 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ * event defined in `ng-model-options`. this method is rarely needed as `NgModelController` * usually handles calling this in response to input events. */ - this.$commitViewValue = function(revalidate) { + this.$commitViewValue = function() { var viewValue = ctrl.$viewValue; $timeout.cancel(pendingDebounce); - if (!revalidate && ctrl.$$lastCommittedViewValue === viewValue) { + if (ctrl.$$lastCommittedViewValue === viewValue && (viewValue !== '' || !ctrl.$$hasNativeValidators)) { return; } ctrl.$$lastCommittedViewValue = viewValue; @@ -2080,14 +2078,14 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ * @param {string} value Value from the view. * @param {string} trigger Event that triggered the update. */ - this.$setViewValue = function(value, trigger, revalidate) { + this.$setViewValue = function(value, trigger) { ctrl.$viewValue = value; if (!ctrl.$options || ctrl.$options.updateOnDefault) { - ctrl.$$debounceViewValueCommit(trigger, revalidate); + ctrl.$$debounceViewValueCommit(trigger); } }; - this.$$debounceViewValueCommit = function(trigger, revalidate) { + this.$$debounceViewValueCommit = function(trigger) { var debounceDelay = 0, options = ctrl.$options, debounce; @@ -2106,10 +2104,10 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ $timeout.cancel(pendingDebounce); if (debounceDelay) { pendingDebounce = $timeout(function() { - ctrl.$commitViewValue(revalidate); + ctrl.$commitViewValue(); }, debounceDelay); } else { - ctrl.$commitViewValue(revalidate); + ctrl.$commitViewValue(); } };