3
Good afternoon, you guys,
I’m having a problem trying to disable a link using jquery.
The problem is this,
There is a table that lists the types of roles a user can have in the system that presents the information in this way :
the buttons of the options have the btnView, btnEdit and btnRemove classes respectively
so far blz.
I want the editing and removal options to be done only by administrators users.
my controller is returning me 1 if the logged in user has Amin and null permission otherwise and adding this value to an input of type Hidden. It is already returning me the permission right however, in javascript, when I command it disable the button if the user is not an administrator nothing happens.
my file is as follows:
HTML
<a href="#" class="show-modal btn btn-info btn-sm btnShow" data-id="{{$papel->id}}" >
<i class="material-icons">remove_red_eye</i>
</a>
<a href="#" class="edit-modal btn btn-warning btn-sm btnEdit" data-toggle="modal"data-target="#create" data-id="{{$papel->id}}" id="btnEdit">
<i class="material-icons" style="color:white">edit</i>
</a>
<a href="#" data-toggle="modal"data-target="#dropPapel" class="delete-modal btn btn-danger btn-sm btnRemove" >
<i class="material-icons">delete</i>
</a>
Javascript
<script>
$(document).ready(function() {
if($('#userAdmin').val()!=1){
console.log('não é admin')
$('.btnRemove').attr('disabled','disabled')
$('.btnShow').attr('disabled','disabled')
$('.btnEdit').attr('disabled','disabled')
}
</script>
I can’t find the problem, if I try to hide the link I can, but if I try to disable it, not even if I tag the disabled property or put attr('disabled',true) does not work. I had already used this same way to disable elsewhere without any problem, but this part is not working. The code is falling in the right condition, is printing on the console the message I sent, but does not disable links
If anyone could shed some light on this, I’d be very grateful.
Thanks in advance
console.log
is executed? Remember to validate on the server side, because thisdisabled
can be bypassed very easily through the browser inspector.– Woss
yes, it prints the message in the console but does not disable the links
– Diego Magno
Ever tried with . prop() and not . attr()? For newer versions of jQuery the most suitable is to use . prop()
– hugocsl
I’ve done that too
– Diego Magno
Vc is using some Javascript framework?
– LeAndrade
It would not be better to remove the links?
– Sam