(scope, element, attr, ctrl, $sniffer, $browser)
| 21897 | } |
| 21898 | |
| 21899 | function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) { |
| 21900 | badInputChecker(scope, element, attr, ctrl); |
| 21901 | baseInputType(scope, element, attr, ctrl, $sniffer, $browser); |
| 21902 | |
| 21903 | ctrl.$$parserName = 'number'; |
| 21904 | ctrl.$parsers.push(function(value) { |
| 21905 | if (ctrl.$isEmpty(value)) return null; |
| 21906 | if (NUMBER_REGEXP.test(value)) return parseFloat(value); |
| 21907 | return undefined; |
| 21908 | }); |
| 21909 | |
| 21910 | ctrl.$formatters.push(function(value) { |
| 21911 | if (!ctrl.$isEmpty(value)) { |
| 21912 | if (!isNumber(value)) { |
| 21913 | throw ngModelMinErr('numfmt', 'Expected `{0}` to be a number', value); |
| 21914 | } |
| 21915 | value = value.toString(); |
| 21916 | } |
| 21917 | return value; |
| 21918 | }); |
| 21919 | |
| 21920 | if (isDefined(attr.min) || attr.ngMin) { |
| 21921 | var minVal; |
| 21922 | ctrl.$validators.min = function(value) { |
| 21923 | return ctrl.$isEmpty(value) || isUndefined(minVal) || value >= minVal; |
| 21924 | }; |
| 21925 | |
| 21926 | attr.$observe('min', function(val) { |
| 21927 | if (isDefined(val) && !isNumber(val)) { |
| 21928 | val = parseFloat(val, 10); |
| 21929 | } |
| 21930 | minVal = isNumber(val) && !isNaN(val) ? val : undefined; |
| 21931 | // TODO(matsko): implement validateLater to reduce number of validations |
| 21932 | ctrl.$validate(); |
| 21933 | }); |
| 21934 | } |
| 21935 | |
| 21936 | if (isDefined(attr.max) || attr.ngMax) { |
| 21937 | var maxVal; |
| 21938 | ctrl.$validators.max = function(value) { |
| 21939 | return ctrl.$isEmpty(value) || isUndefined(maxVal) || value <= maxVal; |
| 21940 | }; |
| 21941 | |
| 21942 | attr.$observe('max', function(val) { |
| 21943 | if (isDefined(val) && !isNumber(val)) { |
| 21944 | val = parseFloat(val, 10); |
| 21945 | } |
| 21946 | maxVal = isNumber(val) && !isNaN(val) ? val : undefined; |
| 21947 | // TODO(matsko): implement validateLater to reduce number of validations |
| 21948 | ctrl.$validate(); |
| 21949 | }); |
| 21950 | } |
| 21951 | } |
| 21952 | |
| 21953 | function urlInputType(scope, element, attr, ctrl, $sniffer, $browser) { |
| 21954 | // Note: no badInputChecker here by purpose as `url` is only a validation |
nothing calls this directly
no test coverage detected