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

153
Visualizações
how to disabled the onclick function if user did not have access for that function?

I have user access function that have data like this. Data read from API

  "allowView": true,
  "allowAdd" : true,
  "allowEdit": false,
  "allowDel" : false

this is how I check the condition for the data. Condition for user access data.

 e.allowView== true ? $("button.viewBtn").prop("disabled",false)  : $("button.viewBtn").prop("disabled",true);
 e.allowAdd== true ? $("button.addBtn").prop("disabled",false)   : $("button.addBtn").prop("disabled",true);
 e.allowEdit== true ? $("button.editBtn").prop("disabled",false)  : $("button.editBtn").prop("disabled",true);
 e.allowDel== true ? $("button.deleteBtn").prop("disabled",false): $("button.deleteBtn").prop("disabled",true);

but I have problem to call the class deleteBtn in <span> because in this line of code did not have button.

  <span class="text-center"><a onclick ="deleteMsg('${emsg_id}')" class=""><span class="text-danger" data-toggle="tooltip" data-placement="top" title="Delete"><em class="icon ni ni-trash"></em></span></a></span>

How do I add the condition in my user access statement so I can use it in my <span> without adding the <button> ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

First of all you can refactor this code so instead of:

e.allowView== true ? $("button.viewBtn").prop("disabled",false)  : $("button.viewBtn").prop("disabled",true);

Can be just:

$("button.viewBtn").prop("disabled", e.allowView != true);

And the second thing, you can in your callback function:

deleteMsg(par) {
if (!e.allowDel)
return false;

// Your existing code...
}

Also you can add some class on your link, so it can add some kind of "disabled" class there...

For example:

if (!e.allowDel) $(selectorToLink).addClass('disabled-link');

.disabled-link {
  pointer-events: none;
}
about 4 years ago · Juan Pablo Isaza Relatório
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