Primefaces how to put background in a Droplist

Asked

Viewed 12 times

0

Well I’m using Primefaces in my project and I came across the following situation, when I have an altered field that is different from the original, I have to leave a background in yellow color more specifically, however that is working in other fields that are inputText but when it is Droplist or Autocomplete does not work, someone has idea how to do?

Code how I’m doing below:

function verificaValorComValorOriginal () {

    debugger;

    // Dados Básicos
    if ($('#nomePessoa').val() != null && $('#nomePessoaOriginal').val() != null) {
        if ($('#nomePessoa').val() != $('#nomePessoaOriginal').val()) {
            $('#nomePessoa').attr("style","background: yellow;");
            $('#nomePessoaOriginal').attr("style","background: yellow;");
        }
    }

    if ($('#apelido').val() != null && $('#apelidoOriginal').val() != null) {
        if ($('#apelido').val()!= $('#apelidoOriginal').val()) {
            $('#apelido').attr("style","background: yellow;");
            $('#apelidoOriginal').attr("style","background: yellow;");
        }
    }

    if ($('#sexo').val() != null && $('#sexoOriginal').val() != null) {
        if ($('#sexo').val() != $('#sexoOriginal').val()) {
            $('#sexo').attr("style","background: yellow;");
            $('#sexoOriginal').attr("style","background: yellow;");
        }
    }

    if ($('#dataNascimento').val() != null && $('#dataNascimentoOriginal').val() != null) {
        if ($('#dataNascimento').val() != $('#dataNascimentoOriginal').val()) {
            $('#dataNascimento').attr("style","background: yellow;");
            $('#dataNascimentoOriginal').attr("style","background: yellow;");
        }
    }

    if ($('#estadoCivil').val() != null && $('#estadoCivilOriginal').val() != null) {
        if ($('#estadoCivil').val() != $('#estadoCivilOriginal').val()) {
            $('#estadoCivil').attr("style","background: yellow;");
            $('#estadoCivilOriginal').attr("style","background: yellow;");
        }
    }

This is a small example of the code, for example this City state is a Droplist and does not work when the value is different. I am using Primefaces 6.2.

Solution:

if ($('#estadoCivil').val() != null && $('#estadoCivilOriginal').val() != null) {
    if ($('#estadoCivil').val() != $('#estadoCivilOriginal').val()) {

        $(".pui-dropdown-label").each(function() {

            if ($(this).context.parentElement.innerHTML.indexOf('estadoCivil') > 0) {
                $(this).attr("style","background: yellow;");
            }

        });
    }
}

For now I got this solution above.

  • Please post the answer as the same answer below. And later you can mark your own answer as accepted. Thank you.

1 answer

0

Solution:

if ($('#estadoCivil').val() != null && $('#estadoCivilOriginal').val() != null) {
    if ($('#estadoCivil').val() != $('#estadoCivilOriginal').val()) {

        $(".pui-dropdown-label").each(function() {

            if ($(this).context.parentElement.innerHTML.indexOf('estadoCivil') > 0) {
                $(this).attr("style","background: yellow;");
            }

        });
    }
}

For now I got this solution above.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.