I have the following problem. I need to validate some fields, which I'm actually doing with formValidator and it works. Once the fields are validated, I send the data by post and ajax and show the sweet alert popup asking if I want to send the form or not. The problem is that when you press the submit button of the form without having filled the required fields, the same alert is shown when it should appear after the success of ajax.
$('#envia_pedidoE').formValidation({
framework: 'bootstrap',
excluded: ':disabled',
fields: {
obs: {
validators: {
notEmpty: {
message: 'Ingrese Obs. de Pedido.'
}
}
},
date: {
validators: {
notEmpty: {
message: 'Seleccione Fecha'
},
date: {
format: 'DD/MM/YYYY',
message: 'Formato Fecha NO VALIDO'
}
}
}
}
});
those are input that is valid (and validates ok).
$('#envia_pedidoE').submit(function(e){
e.preventDefault();
var datos = $(this).serialize();
$.ajax({
type:"POST",
url: "envioE.php",
data : datos,
success:function(data){
var href = "real_pedidos.php";
swal({
title: "Realizará Envío de Pedido",
text: "Para <?php echo $laboratorio;?>",
icon: "info",
buttons: true,
dangerMode: true,
})
.then((envio) => {
if (envio) {
swal("Su Pedidos Fue Enviado Correctamente", {
icon: "success",
});
window.location.href = href;
} else {
swal("Ha Cancelado el Envío del Pedido");
}
});
}
});
});
and that is the ajax with the success that is where I should show the alert asking if I want to send the form.
Any ideas? thank you very much.