So I wanted to make my <tr>'s
clickable / linked to a corresponding page. All rows have a button to delete the row aswell. Unfortunately when an user Clicks on the delete button it still links as the row is clicked. I added code so it would do that except button click.. so it could open the bootstrap modal
for delete confirmation.
My script :
$('tr[data-href]:not(:button)').on("click", function() {
document.location = $(this).data('href');
});
$('tr button[data-target]').on("click", function() {
document.location = $(this).data('target');
});
HTML table with Blade foreach
<tr style="cursor:pointer;!important;" data-href="/bugs/{{$project->id}}">
<td>{{$project->created_at->format('d-m-Y')}}</td>
<td>{{$project->projectnaam}}</td>
<td>{{$project->liveurl}}</td>
<td>{{$project->developmenturl}}</td>
<td>{{$project->user->voornaam .' '. $project->user->tussenvoegsel .' '. $project->user->achternaam }}</td>
<td>{!! substr($project->omschrijvingproject,0,90) !!}</td>
<td class="text-right" >
<a href="/projectmuteren/{{$project->id}}" class="">
<button class="btn btn-success btn-xs wijzigKnop2" name="zoekProject" type="button" data-project="{{$project->projectnaam}}">
<i class="glyphicon glyphicon-pencil"></i>
</button>
</a>
<button type="button" class="btn btn-danger btn-xs" data-toggle="modal" data-target="#myModal{{$project->id}}">
<i class="glyphicon glyphicon-trash"></i>
</button>
</td>
</tr>
Delete modal
<div class="modal fade" id="myModal{{$proj->id}}" tabindex="-1" role="dialog">
<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">Verwijder verzoek</h4>
</div>
<div class="modal-body">
<p>Weet u zeker dat u het project : <strong>{{$proj->titel}}</strong> met alle gekoppelde data wilt verwijderen…</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-xs pull-right" data-dismiss="modal">Sluit</button>
<form method="POST" action="/verwijderProject/{{$proj->id}}" >
{!! method_field('DELETE') !!}
{!! csrf_field() !!}
<button type="submit" class="btn btn-danger btn-xs pull-left">
{{--<i class="glyphicon glyphicon-trash"></i>--}}
Verwijder project
</button>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
Please reply with any solution on how to exclude the button click..