autofill_event_fix.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import coreModule from './core_module';
  2. /** @ngInject */
  3. export function autofillEventFix($compile: any) {
  4. return {
  5. link: ($scope: any, elem: any) => {
  6. const input = elem[0];
  7. const dispatchChangeEvent = () => {
  8. const event = new Event('change');
  9. return input.dispatchEvent(event);
  10. };
  11. const onAnimationStart = ({ animationName }: AnimationEvent) => {
  12. switch (animationName) {
  13. case 'onAutoFillStart':
  14. return dispatchChangeEvent();
  15. case 'onAutoFillCancel':
  16. return dispatchChangeEvent();
  17. }
  18. return null;
  19. };
  20. // const onChange = (evt: Event) => console.log(evt);
  21. input.addEventListener('animationstart', onAnimationStart);
  22. // input.addEventListener('change', onChange);
  23. $scope.$on('$destroy', () => {
  24. input.removeEventListener('animationstart', onAnimationStart);
  25. // input.removeEventListener('change', onChange);
  26. });
  27. },
  28. };
  29. }
  30. coreModule.directive('autofillEventFix', autofillEventFix);