Small javascript library to detect and even prevent browsers autofill of form elements. Usefull for implementing floating labels or applying custom logics/styles.
npm install detect-autofill  !David !David  
* Getting started
* Features
* Browser support
* Demo
1. Import script in the head
``html`
...
...
2. add event listeners
3. do your things...
`js`
document.addEventListener('onautocomplete', function(e) {
e.target.hasAttribute('autocompleted'); // true or false
e.preventDefault(); // prevent autocomplete
// do you stuff...
})
Small javascript library to detect browser autofill of form elements. Usefull for implementing floating labels or appling custom styles.
Modern browsers all have some ability to autocomplete the forms in a web page. It can be a login or a registration form, and the autofill can be triggered automatiaclly by the browser or manually by the user. In both cases there is no native way to detect the autocomplete. This is where this small library comes in handy.
Every browser has it's own way to autocomplete a form. Basically this library creates and triggers a CustomEvent called autocomplete every time this happends.
Furthermore this custom event can be prevented like all native events in order to block browser autofill using e.preventDefault().
* Polyfill for CustomEvent integrated
* CustomEvent on onautocompleteonautocomplete
* CustomEvent on cancelonautocomplete
* Possibility to prevent
| CustomEvent | Edge | IE11 | Chrome | Firefox | Safari | Opera | iOS |
| -------------- |:----:|:-----:|:------:|:-------:|:------:|:-----:|:---:|
| onautocomplete | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
\* This script uses different technics to detect autofill based on the browser:
* Chrome, Opera and Safari uses the pseudo-class :-webkit-autofill to trigger a custom animation.inputType
* Firefox uses input event on document and checks for a propriety property of the event.data` property.
* IE, Edge and iOS uses the same input event but they have to check the
* Android ha not yet been tested any help is welcomed.
The demos can be tested on every browser. If something is not working properly, please open an issue or a PR.
| Title | Source code | Live demo |
| ----- | ----------- | --------- |
| Fake login page | Code | Live |