(scope, element, attr, ctrl, $sniffer, $browser)
| 17074 | var numberBadFlags = ['badInput']; |
| 17075 | |
| 17076 | function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) { |
| 17077 | textInputType(scope, element, attr, ctrl, $sniffer, $browser); |
| 17078 | |
| 17079 | ctrl.$parsers.push(function(value) { |
| 17080 | var empty = ctrl.$isEmpty(value); |
| 17081 | if (empty || NUMBER_REGEXP.test(value)) { |
| 17082 | ctrl.$setValidity('number', true); |
| 17083 | return value === '' ? null : (empty ? value : parseFloat(value)); |
| 17084 | } else { |
| 17085 | ctrl.$setValidity('number', false); |
| 17086 | return undefined; |
| 17087 | } |
| 17088 | }); |
| 17089 | |
| 17090 | addNativeHtml5Validators(ctrl, 'number', numberBadFlags, null, ctrl.$$validityState); |
| 17091 | |
| 17092 | ctrl.$formatters.push(function(value) { |
| 17093 | return ctrl.$isEmpty(value) ? '' : '' + value; |
| 17094 | }); |
| 17095 | |
| 17096 | if (attr.min) { |
| 17097 | var minValidator = function(value) { |
| 17098 | var min = parseFloat(attr.min); |
| 17099 | return validate(ctrl, 'min', ctrl.$isEmpty(value) || value >= min, value); |
| 17100 | }; |
| 17101 | |
| 17102 | ctrl.$parsers.push(minValidator); |
| 17103 | ctrl.$formatters.push(minValidator); |
| 17104 | } |
| 17105 | |
| 17106 | if (attr.max) { |
| 17107 | var maxValidator = function(value) { |
| 17108 | var max = parseFloat(attr.max); |
| 17109 | return validate(ctrl, 'max', ctrl.$isEmpty(value) || value <= max, value); |
| 17110 | }; |
| 17111 | |
| 17112 | ctrl.$parsers.push(maxValidator); |
| 17113 | ctrl.$formatters.push(maxValidator); |
| 17114 | } |
| 17115 | |
| 17116 | ctrl.$formatters.push(function(value) { |
| 17117 | return validate(ctrl, 'number', ctrl.$isEmpty(value) || isNumber(value), value); |
| 17118 | }); |
| 17119 | } |
| 17120 | |
| 17121 | function urlInputType(scope, element, attr, ctrl, $sniffer, $browser) { |
| 17122 | textInputType(scope, element, attr, ctrl, $sniffer, $browser); |
nothing calls this directly
no test coverage detected