Javascript Can';t使用Laravel 5.7取消sweetalert中的删除
我使用的是变色龙甜食警报,我的问题是当我点击取消按钮时,它也会删除该行 以下是我的JS代码:Javascript Can';t使用Laravel 5.7取消sweetalert中的删除,javascript,laravel,Javascript,Laravel,我使用的是变色龙甜食警报,我的问题是当我点击取消按钮时,它也会删除该行 以下是我的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!', ty
$('#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
谢谢大家
我修好了
$('#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'
)
}
})
});
{{{{('delete')}
@csrf
@方法('DELETE')
函数删除类别(id){
游泳({
标题:“你确定吗?”,
文本:“您将无法还原此内容!”,
键入:“警告”,
showCancelButton:true,
confirmButtonColor:“#3085d6”,
cancelButtonColor:“#d33”,
confirmButtonText:'是,删除它!',
cancelButtonText:'不,取消!',
confirmButtonClass:'btn btn success',
取消按钮类:“btn btn危险”,
按钮样式:false,
反转按钮:真
})。然后((结果)=>{
if(result.value){
event.preventDefault();
document.getElementById('delete-form-'+id).submit();
}否则如果(
//了解更多有关处理解雇的信息
result.dismise===swal.DismissReason.cancel
) {
游泳(
“取消”,
“您的数据是安全的:)”,
“错误”
)
}
})
}
它要删除哪一行?您能提供更多详细信息并包含HTML吗?根据他们主页上的示例(确认对话框),变色龙SweetAlert库无法正常工作。@Teemu先生,我需要做的就是设置条件,检查用户是否按“取消SweetAlert消息关闭”且不进行任何更改。这似乎是库本身。您运行“确认对话框”,在模式上单击“取消”,页面提示“您的文件已被删除”,我认为这是一个错误。当您取消表单提交时,这是您的问题。
$('#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'
)
}
})
});
<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>