(scope, element, attr, ctrl, $sniffer, $browser, $filter, $parse)
| 22012 | } |
| 22013 | |
| 22014 | function checkboxInputType(scope, element, attr, ctrl, $sniffer, $browser, $filter, $parse) { |
| 22015 | var trueValue = parseConstantExpr($parse, scope, 'ngTrueValue', attr.ngTrueValue, true); |
| 22016 | var falseValue = parseConstantExpr($parse, scope, 'ngFalseValue', attr.ngFalseValue, false); |
| 22017 | |
| 22018 | var listener = function(ev) { |
| 22019 | ctrl.$setViewValue(element[0].checked, ev && ev.type); |
| 22020 | }; |
| 22021 | |
| 22022 | element.on('click', listener); |
| 22023 | |
| 22024 | ctrl.$render = function() { |
| 22025 | element[0].checked = ctrl.$viewValue; |
| 22026 | }; |
| 22027 | |
| 22028 | // Override the standard `$isEmpty` because the $viewValue of an empty checkbox is always set to `false` |
| 22029 | // This is because of the parser below, which compares the `$modelValue` with `trueValue` to convert |
| 22030 | // it to a boolean. |
| 22031 | ctrl.$isEmpty = function(value) { |
| 22032 | return value === false; |
| 22033 | }; |
| 22034 | |
| 22035 | ctrl.$formatters.push(function(value) { |
| 22036 | return equals(value, trueValue); |
| 22037 | }); |
| 22038 | |
| 22039 | ctrl.$parsers.push(function(value) { |
| 22040 | return value ? trueValue : falseValue; |
| 22041 | }); |
| 22042 | } |
| 22043 | |
| 22044 | |
| 22045 | /** |
nothing calls this directly
no test coverage detected