I have a text input with minlength defined. When a user enters text, the input's validity state is updated immediately. If I alter the value in code, the validity state reset to show as valid -- even with a constraint violated, validity.valid is true.
const input = document.getElementById("input");
const label = document.getElementById("label");
document.getElementById("rightButton").addEventListener("click", evt => {
input.value = "ABCDE";
});
document.getElementById("wrongButton").addEventListener("click", evt => {
input.value = "AB";
});
setInterval(() => label.innerHTML = input.validity.valid, 250);
<input type="text" id="input" minlength="4">
<span id="label"></span>
<hr/>
<button id="rightButton">Make It Right</button>
<button id="wrongButton">Make It Wrong</button>
Why doesn't automatic validity checking run when I assign to input.value? Is this documented somewhere? Is there a method I can call to trigger the browser's internal validation process, rather than having to do my own checks and call setCustomValidity?
checkValidity()after assigning a value toinput.valuebut it always returns true.<input type="date">fields. A JSFiddle illustrating the problem can be found here: jsfiddle.net/thetetet/rmpw7s4y/35 The "last changed by a user edit" note seems to be true for any of the constraint checks for theValueStateinformation, as pointed out below at stackoverflow.com/a/53261163/1337474