MCPcopy Create free account
hub / github.com/cafebazaar/blacksmith / checkboxInputType

Function checkboxInputType

web/static/bower_components/angular/angular.js:22014–22042  ·  view source on GitHub ↗
(scope, element, attr, ctrl, $sniffer, $browser, $filter, $parse)

Source from the content-addressed store, hash-verified

22012}
22013
22014function 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/**

Callers

nothing calls this directly

Calls 2

parseConstantExprFunction · 0.85
equalsFunction · 0.85

Tested by

no test coverage detected