I have a dialog that checks if user really wants to save the data when a vehicle exceed kilometers params. The dialog is shown in the correct moment, but the code continues and save the data before the user says yes or no to that option.
I put the code below:
if(vehicleIDkm > 0){
//Instrucciones para comprobar si no supera la media de kilometros del vehiculo
$.ajax({
url: "getVehicleKMmax.json?vehicleId=" + vehicleIDkm,
method: 'GET',
dataType: "json",
async: false,
contentType: 'application/json',
success: function(kmMaxVehicle){
if(kilometrosLlegada - kilometrosSalida > kmMaxVehicle){
// Abrir la ventana para informar y pedir confirmacion
$("#dialog-activity-data-confirm").dialog({
resizable: false,
height: 300,
width: 400,
modal: true,
async: false,
dialogClass: "confirmDialogClass",
title: "Exceso de kilómetros",
open: function() {
var markup = 'Ha excedido la cantidad de kilometros a realizar en un dia por este vehiculo, ¿quiere guardar la producción igualmente? De ser así, pulse en continuar, si no, cierre esta ventana.';
$(this).html(markup);
},
buttons:
[
{
text: "Continuar",
"class": "buttonTextDelete roundedButton roundedButtonAccent confirmBG",
click: function() {
sePuedeGuardar = true;
noSePuedeGuardarPorKilometros = false;
$(this).dialog('close');
}
}
],
close: function() {
sePuedeGuardar = false;
noSePuedeGuardarPorKilometros = true;
}
});
}
},
error: function(error){
console.log("Se ha producido un error al comprobar si es festivo el día.");
}
});
}
if(sePuedeGuardar){
// Guardamos los datos
$.ajax({
type: "POST",
url: finalUrl,
...
...
...
As you see, I use a variable "sePuedeGuardar" to check if you can save or not the data, but it always go in that if, no matter if it is true or false, because it goes there before the user answer the dialog question.
Can anyone help me? Thanks!