diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index 26af20d5f5ae..b9b3ed684db5 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -1781,6 +1781,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ */ this.$commitViewValue = function() { var viewValue = ctrl.$viewValue; + $timeout.cancel(pendingDebounce); if (ctrl.$$lastCommittedViewValue === viewValue) { return; @@ -2130,21 +2131,12 @@ var requiredDirective = function() { if (!ctrl) return; attr.required = true; // force truthy in case we are on non input element - var validator = function(value) { - if (attr.required && ctrl.$isEmpty(value)) { - ctrl.$setValidity('required', false); - return; - } else { - ctrl.$setValidity('required', true); - return value; - } + ctrl.$validators.required = function(modelValue, viewValue) { + return !attr.required || !ctrl.$isEmpty(viewValue); }; - ctrl.$formatters.push(validator); - ctrl.$parsers.unshift(validator); - attr.$observe('required', function() { - validator(ctrl.$viewValue); + ctrl.$validate(); }); } }; diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index b18c3c2d9109..2bb5073b89d3 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -2564,7 +2564,7 @@ describe('input', function() { compileInput(''); scope.$apply(function() { - scope.name = ''; + scope.name = null; }); expect(inputElm).toBeInvalid();