(scope, element, attr, ctrl, $sniffer, $browser)
| 19801 | } |
| 19802 | |
| 19803 | function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) { |
| 19804 | badInputChecker(scope, element, attr, ctrl); |
| 19805 | baseInputType(scope, element, attr, ctrl, $sniffer, $browser); |
| 19806 | |
| 19807 | ctrl.$$parserName = 'number'; |
| 19808 | ctrl.$parsers.push(function(value) { |
| 19809 | if (ctrl.$isEmpty(value)) return null; |
| 19810 | if (NUMBER_REGEXP.test(value)) return parseFloat(value); |
| 19811 | return undefined; |
| 19812 | }); |
| 19813 | |
| 19814 | ctrl.$formatters.push(function(value) { |
| 19815 | if (!ctrl.$isEmpty(value)) { |
| 19816 | if (!isNumber(value)) { |
| 19817 | throw $ngModelMinErr('numfmt', 'Expected `{0}` to be a number', value); |
| 19818 | } |
| 19819 | value = value.toString(); |
| 19820 | } |
| 19821 | return value; |
| 19822 | }); |
| 19823 | |
| 19824 | if (attr.min || attr.ngMin) { |
| 19825 | var minVal; |
| 19826 | ctrl.$validators.min = function(value) { |
| 19827 | return ctrl.$isEmpty(value) || isUndefined(minVal) || value >= minVal; |
| 19828 | }; |
| 19829 | |
| 19830 | attr.$observe('min', function(val) { |
| 19831 | if (isDefined(val) && !isNumber(val)) { |
| 19832 | val = parseFloat(val, 10); |
| 19833 | } |
| 19834 | minVal = isNumber(val) && !isNaN(val) ? val : undefined; |
| 19835 | // TODO(matsko): implement validateLater to reduce number of validations |
| 19836 | ctrl.$validate(); |
| 19837 | }); |
| 19838 | } |
| 19839 | |
| 19840 | if (attr.max || attr.ngMax) { |
| 19841 | var maxVal; |
| 19842 | ctrl.$validators.max = function(value) { |
| 19843 | return ctrl.$isEmpty(value) || isUndefined(maxVal) || value <= maxVal; |
| 19844 | }; |
| 19845 | |
| 19846 | attr.$observe('max', function(val) { |
| 19847 | if (isDefined(val) && !isNumber(val)) { |
| 19848 | val = parseFloat(val, 10); |
| 19849 | } |
| 19850 | maxVal = isNumber(val) && !isNaN(val) ? val : undefined; |
| 19851 | // TODO(matsko): implement validateLater to reduce number of validations |
| 19852 | ctrl.$validate(); |
| 19853 | }); |
| 19854 | } |
| 19855 | } |
| 19856 | |
| 19857 | function urlInputType(scope, element, attr, ctrl, $sniffer, $browser) { |
| 19858 | // Note: no badInputChecker here by purpose as `url` is only a validation |
nothing calls this directly
no test coverage detected