(scope, element, attr, ctrl, $sniffer, $browser)
| 16974 | } |
| 16975 | |
| 16976 | function textInputType(scope, element, attr, ctrl, $sniffer, $browser) { |
| 16977 | var validity = element.prop(VALIDITY_STATE_PROPERTY); |
| 16978 | var placeholder = element[0].placeholder, noevent = {}; |
| 16979 | var type = lowercase(element[0].type); |
| 16980 | ctrl.$$validityState = validity; |
| 16981 | |
| 16982 | // In composition mode, users are still inputing intermediate text buffer, |
| 16983 | // hold the listener until composition is done. |
| 16984 | // More about composition events: https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent |
| 16985 | if (!$sniffer.android) { |
| 16986 | var composing = false; |
| 16987 | |
| 16988 | element.on('compositionstart', function(data) { |
| 16989 | composing = true; |
| 16990 | }); |
| 16991 | |
| 16992 | element.on('compositionend', function() { |
| 16993 | composing = false; |
| 16994 | listener(); |
| 16995 | }); |
| 16996 | } |
| 16997 | |
| 16998 | var listener = function(ev) { |
| 16999 | if (composing) return; |
| 17000 | var value = element.val(); |
| 17001 | |
| 17002 | // IE (11 and under) seem to emit an 'input' event if the placeholder value changes. |
| 17003 | // We don't want to dirty the value when this happens, so we abort here. Unfortunately, |
| 17004 | // IE also sends input events for other non-input-related things, (such as focusing on a |
| 17005 | // form control), so this change is not entirely enough to solve this. |
| 17006 | if (msie && (ev || noevent).type === 'input' && element[0].placeholder !== placeholder) { |
| 17007 | placeholder = element[0].placeholder; |
| 17008 | return; |
| 17009 | } |
| 17010 | |
| 17011 | // By default we will trim the value |
| 17012 | // If the attribute ng-trim exists we will avoid trimming |
| 17013 | // If input type is 'password', the value is never trimmed |
| 17014 | if (type !== 'password' && (toBoolean(attr.ngTrim || 'T'))) { |
| 17015 | value = trim(value); |
| 17016 | } |
| 17017 | |
| 17018 | // If a control is suffering from bad input, browsers discard its value, so it may be |
| 17019 | // necessary to revalidate even if the control's value is the same empty value twice in |
| 17020 | // a row. |
| 17021 | var revalidate = validity && ctrl.$$hasNativeValidators; |
| 17022 | if (ctrl.$viewValue !== value || (value === '' && revalidate)) { |
| 17023 | if (scope.$$phase) { |
| 17024 | ctrl.$setViewValue(value); |
| 17025 | } else { |
| 17026 | scope.$apply(function() { |
| 17027 | ctrl.$setViewValue(value); |
| 17028 | }); |
| 17029 | } |
| 17030 | } |
| 17031 | }; |
| 17032 | |
| 17033 | // if the browser does support "input" event, we are fine - except on IE9 which doesn't fire the |
no test coverage detected