Minimal example
let input = document.createElement("input");
input.id = "input";
input.type = "number";
input.className = "number-input";
input.disabled = true;
document.body.appendChild(input);
.number-input:focus {
background: yellow;
}
.number-input {
-moz-appearance: textfield;
}
<button onClick="document.getElementById('input').disabled = false">
Enable
</button>
<button onClick="document.getElementById('input').disabled = true">
Disable
</button>
The created input
is semi-disabled on start, i. e. you can click on it and it turns yellow (gets focus), but you can't write a number into it. However after clicking Enable followed by Disable button, it is as disabled as expected. It seems to be a bug that involves the input.type = "number"
and the browser specific -moz-appearance: textfield
, that I use to hide the up and down buttons.
Any ideas how to really disable the input field, when the page is loaded?