I'm having trouble displaying html5 inline validation bubble without using submit button. I can't use jQuery, only vanilla javascript.
This is my html:
<a id="send" href="#">Send</a>
<form id="sendform" action="">
<input type="email" placeholder="E-mail" id="email-add" required>
</form>
And this is my javascript:
var btn = document.getElementById('send');
var emailField = document.getElementById('email-field');
btn.addEventListener('click',function() {
// remove validation message
emailField.setCustomValidity('');
if (!emailField.validity.valid) {
// set custom validation message
emailField.setCustomValidity('Custom error message!');
// add CSS class
emailField.className = 'invalid';
}
});
When clicking on anchor, I want to trigger validation bubble with custom message, but bubble doesn't show up. If I use submit button inside a form, bubble is there.
Here is an example: https://jsfiddle.net/esedic/rc8va4vf/
Any ideas?