dhtmlx.confirm does not close when calling form send

Good day,

I’m trying to use dhtmlx.confirm on my application to ask users if they are sure they want to save changes to data.

Here is my code:

[code]attachEvent(“onAfterValidate”, function (status){
if(status)
{
var guardaAlumno = function()
{
send(“data/alumnos.php”, function(xml){
muestraResultado(xml);
});
}
confirmar(“Esta seguro que desea guardar los cambios?”, guardaAlumno);
}
else
{
alertar(“Existen errores en el formulario”);
}
});

function confirmar(msg, func){
dhtmlx.confirm({
text: msg,
ok:“Aceptar”, cancel:“Cancelar”,
callback: function(result){
if(result)
func();
}
});
}[/code]

muestraResultado(xml) is just a function that displays a green message if it was successful or red message if not.

The code before executes correctly but does not close the confirm messagebox. But if I change the form.send, to something which doesn’t involve an asynchronous call, the the confirm messagebox closes correctly.

Any help will be appreciated. :frowning:

Are you sure that send operation is async ?
It it sync or involves current page reloading - it can cause the described problematic behavior.

Anyway, you can add timeout call to run custom function only after confirm closing

Change

  if(result)  func(); 

as

  if(result)  setTimeout(func,1);

I couldn’t make it work with your proposed solution. I rewrote the code like this:

dhtmlx.confirm("Esta seguro que desea guardar los cambios?",function(result){
					if(result)
					{
						send("data/alumnos.php", function(xml){
							var response = muestraResultado(xml);
							if(response.status == "ok")
							{
								frmsel.setItemValue("registro",getItemValue("registro"));
								frmsel.setItemValue("nombre",getItemValue("nombres") + " " + getItemValue("apellidos"));
								frmsel.setItemValue("id",response.id);
							}
						});
					}
				});

But issue still remains. Please help me.

I found the cause of the problem. Confirm window gets closed when “Ok” button is pressed, but when the form’s response comes back from the server, the window is shown again. Could you please tell me what would be the best way to include a confirm message before sendind the form data to the server.

Thank you. :smiley:

Try to reorganize your code like next

[code]function send_form(){
send(“data/alumnos.php”, function(xml){
var response = muestraResultado(xml);
if(response.status == “ok”)
{
frmsel.setItemValue(“registro”,getItemValue(“registro”));
frmsel.setItemValue(“nombre”,getItemValue(“nombres”) + " " + getItemValue(“apellidos”));
frmsel.setItemValue(“id”,response.id);
}
});
};

dhtmlx.confirm(“Esta seguro que desea guardar los cambios?”,function(result){
if (result) setTimeout(send_form, 1);
});
[/code]