I have an email and a password input with required and instead of "Please fill out this field.", I want a message in another language.
I found from relevant questions that I must use the setCustomValidity() but I don't know how to implement it correctly since the examples were using inline JavaScript or jQuery or they changed the message for one input.
While using this code:
function validate() {
const inputs = document.getElementsByTagName('input');
for (let input of inputs) {
let validityState = input.validity;
if (validityState.valueMissing) {
input.setCustomValidity('Παρακαλώ συμπλήρωσε το πεδίο.');
} else if (validityState.typeMismatch) {
input.setCustomValidity('Πρέπει να υπάρχει ένα «@»!')
} else {
input.setCustomValidity('');
}
input.reportValidity();
}
}
document.getElementsByTagName('input').innerHTML = validate();
I was able to change the language but I noticed that when I typed on the email input, the validity message would stay even if the input wasn't empty!