Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
How to change the language of the validity message for all the inputs using JavaScript?

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!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda