我正在使用Chameleon SweetAlert,我的问题是当我单击取消按钮时,它也会删除行
下面是我的JS代码:
$('#confirm-dialog').on('click', function (e) {
var that = $(this)
e.preventDefault();
swal({
title: 'Are you sure?',
text: 'You won\'t be able to revert this!',
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then(function () {
that.closest('form').submit();
swal('Deleted!', 'Your file has been deleted!', 'success')
}).catch(swal.noop)
});这是刀片代码:
@if (auth()->user()->hasPermission('delete_agents'))
<form action="{{ route('dashboard.agents.destroy', $agent->id) }}" method="post" style="display: inline-block">
{{ csrf_field() }}
{{ method_field('delete') }}
<button type="button" class="btn btn-outline-danger btn-min-width box-shadow-5 mr-1 mb-1 " id="confirm-dialog"><i class="fa fa-trash"></i> @lang('site.delete')</button>
</form><!-- end of form -->
@else
<button class="btn btn-outline-danger btn-min-width box-shadow-5 mr-1 mb-1 disabled"><i class="fa fa-trash"></i> @lang('site.delete')</button>
@endif下面是控制器代码:
public function destroy(Agent $agent)
{
$agent->delete();
session()->flash('success', __('site.deleted_successfully'));
return redirect()->route('dashboard.agents.index');
}发布于 2020-01-13 17:01:20
谢谢大家
我已经修好了
$('#confirm-dialog').on('click', function (e) {
var that = $(this)
e.preventDefault();
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.value) {
that.closest('form').submit();
Swal.fire(
'Deleted!',
'Your file has been deleted.',
'success'
)
}
})
});发布于 2020-01-15 15:28:18
<button class="btn btn-danger waves-effect" type="button" onclick="deletecategory({{ $category->id }})"> <i class="material-icons">{{__('delete')}}</i>
</button>
<form id="delete-form-{{ $category->id }}" action="{{
route('admin.category.destroy',$category->id) }}" method="POST" style="display: none;">
@csrf
@method('DELETE')
</form>
<script type="text/javascript">
function deletecategory(id) {
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!',
cancelButtonText: 'No, cancel!',
confirmButtonClass: 'btn btn-success',
cancelButtonClass: 'btn btn-danger',
buttonsStyling: false,
reverseButtons: true
}).then((result) => {
if (result.value) {
event.preventDefault();
document.getElementById('delete-form-'+id).submit();
} else if (
// Read more about handling dismissals
result.dismiss === swal.DismissReason.cancel
) {
swal(
'Cancelled',
'Your data is safe :)',
'error'
)
}
})
}
</script>https://stackoverflow.com/questions/59712786
复制相似问题