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

188
Visualizações
Form validation using JQuery & CSS

I have a requirement where I need to validate my form using JavaScript and displaying a Tooltip inside the Valid/Invalid field.

How can I write a conditional where IF the user enters the correct number a tick appears inside the field and IF it's false, it shows an error tooltip with a message detailing what the error is.

Ideally, I want to connect the JS code to an :valid,:invalid CSS pseudo class.

Here is a condition I currently use in my form:

//Assignment Number Validation - [Wizard 2]
  fd.spRendered(function() {
    fd.field('Assignment_x0020_Number_x0020_').validators.push({
        name: '',
        error: '',
        validate: function(value) {
            if ((/^\d{8}(-\d{1,2})?$/).test(value)) {
            $($(fd.field('Title').$el).find('input')[0]).attr('style', 'color:green');
            return true; // Validation succeded
            }
            // You land here if it did not succeed
            this.error = 'Invalid Assignment Number. Please enter a minimum of 8 digits.';
           $($(fd.field('Title').$el).find('input')[0]).attr('style', 'color:red');
            return false;
        }
    });
});

Can I negate this:

$($(fd.field('Title').$el).find('input')[0]).attr('style', 'color:green');
$($(fd.field('Title').$el).find('input')[0]).attr('style', 'color:red');

Replace with:

.fd-form .form-control.is-invalid{
  color: red!important;
}

.fd-form .form-control.is-valid{
  color: red!important;
}

I feel as though JQuery has some limitations in terms of styling, so I think the CSS above will provide more customisability.

In a nutshell, my question is: Will the form still validate with the :valid & :invalid CSS classes automatically or will I need to add something in the JS Script to 'Target' the :valid & :invalid CSS classes?

Any guidance on how I can approach this would be much appreciated.

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