I have the following code:
document.getElementById('testSubmit').addEventListener('click', (e) => {
e.preventDefault();
document.getElementById('test').setCustomValidity('THIS WILL ALWAYS BE AN ERROR, how do I display this message?');
console.log(document.getElementById('test').validationMessage);
});
<input id = "test" type = "email" required>
<input id = "testSubmit" type = "submit">
As you can see, I can indicate that an error happens in the input field. However, I would like to display the message in my input.validationMessage which is set by setCustomValidity method in my error popup (which does not appear). How do I make the UI validation error popup to appear. For reference, the popup I'm referring to can be seen in the following code:
document.getElementById('btn-submit').addEventListener("click", function() {
if (!document.getElementById('form').checkValidity()) {
document.getElementById("submit-hidden").click();
}
});
<form id="form" action="">
<input type="text" required />
<input id="submit-hidden" type="submit" style="display: none" />
</form>
<button id="btn-submit">Submit</button>
Which displays the popup 'Please fill out this field' when you submit without filling the field. How do I trigger that popup, but with my custom validation message?