Last active
March 29, 2023 02:13
-
-
Save dtarnawsky/fc92869c1c67b9c74c66de8af3e081b2 to your computer and use it in GitHub Desktop.
Directive to help autofill an ion-input for iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, ElementRef, OnInit } from '@angular/core'; | |
import { Capacitor } from '@capacitor/core'; | |
@Directive({ | |
selector: '[appAutofill]' | |
}) | |
export class AutofillDirective implements OnInit { | |
constructor(private el: ElementRef) { | |
} | |
ngOnInit(): void { | |
if (Capacitor.getPlatform() !== 'ios') { return; }; | |
setTimeout(() => { | |
try { | |
this.el.nativeElement.children[0].addEventListener('change', (e) => { | |
this.el.nativeElement.value = (e.target as any).value; | |
}); | |
} catch { } | |
}, 100); // Need some time for the ion-input to create the input element | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ended up coming across this issue as well with vue. I converted the above to a vue directive. Example usage below.
Vue Directive
Example