Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(input): $render input even if $modelValue is empty #9681

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '');
};
}

Expand Down
16 changes: 16 additions & 0 deletions test/ng/directive/inputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ describe('NgModelController', function() {

});


describe('validations pipeline', function() {

it('should perform validations when $validate() is called', function() {
Expand Down Expand Up @@ -2075,6 +2076,21 @@ describe('input', function() {
expect(inputElm.val()).toBe('0');
});

it('should render the $viewValue when $modelValue is empty', function() {
compileInput('<input type="text" ng-model="value" />');

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() {

Expand Down