I am trying to attach a click handler on an input, but for some reason it doesn't work for first click on inputs that get autosuggestion
in safari. All other clicks after the first one work. So for example if an input has a name or label before it saying First name
, Last name
, Email
or anything similar Safari will put a suggestion widget at the end of the input and suggest my information that is in Keychain Access I guess. Click event will not trigger the first time I click on that input, after the first one it triggers ok.
Here is the code that produces this issue. Basically I need a way to trigger a click event on inputs every time it gets clicked (preferably vanilla js, but jquery would be ok too).
HTML:
<form>
// Click on this input doesn't trigger the first time I click it because Safari has a suggestion widget for this input
<label for="email">Email</label>
<input type="email" class="form-control" id="email" placeholder="you@example.com" data-input="">
// Click on this input triggers every time I click it with no issue
<label for="address">Address</label>
<input type="text" class="form-control" id="address" placeholder="1234 Main St" required="" data-input="">
</form>
JS:
var inputs = document.querySelectorAll('[data-input]');
var myFunction = function(event) {
console.log('Clicked');
};
for (var i = 0; i < inputs.length; i++) {
// I put this console.log here to see if all of the inputs pass through this for loop to get the event listener and they do
console.log(inputs[i]);
inputs[i].addEventListener('click', myFunction);
}
EDIT: even though @gopigorantala's link in his comment might be considered duplicate, I am not looking for the same thing that question is looking for. That question asks for a way to disable safari autosuggestion feature on inputs, I am looking for a way to detect clicks on inputs despite autosuggestion being there.