Skip to content

Commit

Permalink
fix(input): set ngTrueValue on required checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Narretz authored and petebacondarwin committed Nov 21, 2014
1 parent 006b078 commit 187654c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -1338,9 +1338,11 @@ function checkboxInputType(scope, element, attr, ctrl, $sniffer, $browser, $filt
element[0].checked = ctrl.$viewValue;
};

// Override the standard `$isEmpty` because a value of `false` means empty in a checkbox.
// Override the standard `$isEmpty` because the $viewValue of an empty checkbox is always set to `false`
// This is because of the parser below, which compares the `$modelValue` with `trueValue` to convert
// it to a boolean.
ctrl.$isEmpty = function(value) {
return value !== trueValue;
return value === false;
};

ctrl.$formatters.push(function(value) {
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 @@ -2255,6 +2255,22 @@ describe('input', function() {
});


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

it('should validate in-lined pattern', function() {
Expand Down

0 comments on commit 187654c

Please sign in to comment.