I have a confirmation message in my form with JS script but the value of "verif" always false or I do not know where is the problem; If I boot "verif" with false, it's still false
function valider() {
var verif = false;
swal({
title: "Are you sure?",
text: "You will not be able to recover this file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel plx!",
closeOnConfirm: false,
closeOnCancel: false
}, function(isConfirm) {
if (isConfirm) {
swal("Deleted!", "Your file has been deleted.", "success");
verif = true;
alert("afficher");
} else {
swal("Cancelled", "Your file is safe :)", "error");
verif = false;
swal("afficher");
}
});
if (verif) {
$("#formulaire").submit();
}
return false;
}
$("#envoyer").click(function() {
valider();
return false;
});
and this is the HTML Code
<form action="archi.php" method="post" class="form-horizontal" id="formulaire">
<div class="form-actions">
<button type="submit" id="envoyer" class="btn blue envoyer"> <i class="icon-save"></i> Archiver</button>
<button type="button" class="btn">Cancel</button>
</div>
</form>
Why do you add another test for submitting? Add submit to the callback function and delete additional if
:
function valider() {
var verif = false;
swal({
title: "Are you sure?",
text: "You will not be able to recover this file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel plx!",
closeOnConfirm: false,
closeOnCancel: false
}, function(isConfirm) {
if (isConfirm) {
$("#formulaire").submit();
swal("Deleted!", "Your file has been deleted.", "success");
} else {
swal("Cancelled", "Your file is safe :)", "error");
swal("afficher");
}
});
return false;
}
$("#envoyer").click(function() {
valider();
return false;
});
P.S. Try adding a console.log()
before the return from verif()
function to check if the }, function(isConfirm) {
is async (this would clarify all misunderstanding).
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments