我正在参与一个Laravel项目,我有一个" bug"当我尝试从数据库中删除一个城市时。
当我按下删除按钮时,首先要做的是打开一个模态,我需要确认删除或取消它。
我的问题:当我按下删除按钮时,模式会打开,但表格会继续前进而无需等待确认。
脚本:
$('#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();
});
按钮:
<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() !!}
模态:
<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>
答案 0 :(得分:2)
将按钮类型更改为按钮而不是提交。 'type'=&gt; '按钮'