I'm working on a Laravel project and I have a "bug" when I attempt to delete a city from the database.
When I press the Delete button, the first thing what needs to happen is opening a modal where I need to confirm the delete or cancel it.
My problem: when I press the Delete button, the modal opens, but the form goes on forward without waiting for confirmation.
Script:
$('#confirmDelete').on('show.bs.modal', function (e) {
e.preventDefault();
$message = $(e.relatedTarget).attr('data-message');
$(this).find('.modal-body p').text($message);
$title = $(e.relatedTarget).attr('data-title');
$(this).find('.modal-title').text($title);
// Pass form reference to modal for submission on yes/ok
var form = $(e.relatedTarget).closest('form');
$(this).find('.modal-footer #confirm').data('form', form);
});
<!-- Form confirm (yes/ok) handler, submits form -->
$('#confirmDelete').find('.modal-footer #confirm').on('click', function(){
$(this).data('form').submit();
});
Button:
<div class="col-md-4">
{!! Form::open(['method' => 'DELETE','action' => ['AdminController@brisanjegrada', $gradovi->id],'style' => 'display:inline']) !!}
{{ Form::button('<i class="fa fa-trash">Obrišite Grad</i>', ['type' => 'submit', 'class' => 'btn btn-danger',' data-toggle'=>'modal','data-target'=>'#confirmDelete','data-title'=>'Brisanje županije','data-message'=>'Da li ste sigurni da želite obrisati grad'] ) }}
{!! Form::close() !!}
Modal:
<div class="modal fade" id="confirmDelete" role="dialog" aria-labelledby="confirmDeleteLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"></h4>
</div>
<div class="modal-body">
<p></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Natrag</button>
<button type="button" class="btn btn-danger" id="confirm">Obriši</button>
</div>
</div>
</div>
</div>
Change the Button type to button instead of submit. 'type' => 'button'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.