Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda