I am trying to use sweet alert in yii in place on the confirmation option.
I have an ajax button and I would like the sweet alert to pop up, once the user has chosen confirm or cancel I can then either continue with the ajax request or stop.
'ajax' => array(
'url'=>CController::createUrl('items/delete'),
'type'=>'POST',
'async'=>true,
'data'=>array('Item'=>$item['Item_id']),
'dataType'=>'json',
'enctype'=>'multipart/form-data',
'cache'=>false,
'beforeSend'=>'js:function(data)
{
var x = sweetalertDelete();
if(x){alert("aaaaaaa"); return true;}
else {alert("bbbbb"); return false;}
}',
'success'=>'function(data)
{
I am using beforesend in order to display the sweet alert box. The issue is that as soon as the the box appears, x is returned and the alerts seen later are then shown. Here is my sweet alert code:
function sweetalertDelete(){
swal({
title: "<?php echo Yii::t('app','misc.order_delete'); ?>",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false,
closeOnCancel: false
},
function (isConfirm) {
//swal("Deleted!", "Your imaginary file has been deleted.", "success");
if (isConfirm) {
alert("true");
return true;
}
else
{
alert("false");
return false;
}
});
}
My question is how I can make it so that the value of isconfirm is returned and until the confirm/cancel button is clicked, the ajax request will not be sent.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire