From b2fa90a57d28a7be3fafce95543431228bc41888 Mon Sep 17 00:00:00 2001 From: Martin Staffa Date: Sun, 19 Oct 2014 18:26:07 +0200 Subject: [PATCH] fix(input): $render input even if $modelValue is empty $render should only be concerned if there is a $viewValue present. When we check $isEmpty($modelValue), we assume $render is used in context of a model -> view update. But since it is part of the public API, it needs to work independent of internal usage. Fixes #9156 --- src/ng/directive/input.js | 2 +- test/ng/directive/inputSpec.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index 69d5149fa1a9..2dd1dc32a859 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -1029,7 +1029,7 @@ function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) { element.on('change', listener); ctrl.$render = function() { - element.val(ctrl.$isEmpty(ctrl.$modelValue) ? '' : ctrl.$viewValue); + element.val(ctrl.$viewValue || ''); }; } diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index 0366aa786aaa..a7d46e4c936a 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -484,6 +484,7 @@ describe('NgModelController', function() { }); + describe('validations pipeline', function() { it('should perform validations when $validate() is called', function() { @@ -2075,6 +2076,21 @@ describe('input', function() { expect(inputElm.val()).toBe('0'); }); + it('should render the $viewValue when $modelValue is empty', function() { + compileInput(''); + + var ctrl = inputElm.controller('ngModel'); + + ctrl.$modelValue = null; + + expect(ctrl.$isEmpty(ctrl.$modelValue)).toBe(true); + + ctrl.$viewValue = 'abc'; + ctrl.$render(); + + expect(inputElm.val()).toBe('abc'); + }); + describe('pattern', function() {