fix(input): set ngTrueValue on required checkbox

Fixes #5164
This commit is contained in:
Martin Staffa
2014-11-21 19:47:43 +00:00
committed by Peter Bacon Darwin
parent 40406e2f22
commit 8692f87a46
2 changed files with 20 additions and 2 deletions

View File

@@ -1342,9 +1342,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) {

View File

@@ -2290,6 +2290,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() {