https://codepen.io/durja/pen/BPmmyR
I am trying to implement custom error messages for a form using the constraint api in html. Below is my code and I am facing an issue where after entering a wrong input and correcting it again, the validation message is still showing up. I am not sure what I am missing. I even tried to check the validity using checkValidity() method which is returning false even though the input is of the correct pattern.
const fp = document.getElementById('quantity');
const ide = document.getElementById('ide_pref');
fp.addEventListener('input',e => {
console.log(e.target.value);
if(fp.validity.rangeOverflow) {
fp.setCustomValidity('Custom message: greater than 100 not allowed.');
}
});
ide.addEventListener('input',e => {
console.log(e.target.value);
console.log(ide.checkValidity());
if(ide.validity.patternMismatch) {
ide.setCustomValidity('enter exactly webstorm OR vscode');
}
})