0
I have a button
calling a modal for exclusion confirmation, this is in a table, each row a button
to delete the registration of that line
But the way it is he always deletes the first item from the list
<button type="button" id="btn-modal" cidadao-id="{{$cidadao->id}}" class="btn-modal" data-toggle="modal" data-target="#modal-default">{{$cidadao->id}}</button>
<div class="modal fade" id="modal-default">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title">Confirmação</h4>
</div>
<div class="modal-body">
<p>Deseja realmente excluir o cadastro?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Fechar</button>
<form id="formdelete" class="form-vertical" method="POST" action="{{ action('CidadaoController@destroy', $cidadao->id)}}">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-primary">{{$cidadao->id}}</button>
</form>
</div>
</div>
</div>
</div>
I managed to capture the correct id with JS:
$('.btn-modal').click(function(){
var id = $(this).attr('cidadao-id');
console.log(id);
//document.formdelete.action = "{{ action('CidadaoController@destroy', id)}}";
})
I tried to replace the action to use the id I captured, but it didn’t work
How could I delete the registration of the captured id?
I have tested how it is and has worked https://jsfiddle.net/ph3rx4bc/1/
– Wictor Chaves
I only recommend changing citizenship-id to date-citizenship-id and use instead of attr data https://jsfiddle.net/ph3rx4bc/4/
– Wictor Chaves
@Wictorchaves thanks I’ll do it, but as for recovering the id in modal I wouldn’t know how?
– Mateus