myForm.save(); myForm.unload() - causes error

Hello, Support Team!

I have modal window with form.
After click “Save” button I need save data, unload myForm and modal window.

var formWin = dhtmlxWin.createWindow('formWin', 0, 0, 320, 240);
//define form
var str = [ .... ];
var newClientForm = formWin.attachForm(str);
newClientForm.attachEvent("onButtonClick",function(buttonID){
			    if(buttonID=="save") {
                  newClientForm.save();
           } 
           newClientForm.unload(); 
           formWin.close();
});

The data saved but I get follow error
“TypeError: this.obj.getUserData is not a function”
I suspect the reason is order of execution. My form unloaded before save operation completed.
If insert “alert(“closing Window”);” between “save()” and “unload()”

newClientForm.attachEvent("onButtonClick",function(buttonID){
			    if(buttonID=="save") {
                  newClientForm.save();
            } 
            alert("closing Window");
            newClientForm.unload(); 
            formWin.close();
});

In that case I don’t see error.

Please advice me, how to release resources of window with form (complex form with calendar)?

Hi

please provide completed demo incliding all corresponding js/css uncompressed files

var formWin = dhtmlxWin.createWindow(‘formWin’, 0, 0, 320, 240);
//define form
var str = [ … ];
var newClientForm = formWin.attachForm(str);
newClientForm.attachEvent(“onButtonClick”,function(buttonID){
if(buttonID==“save”) {
newClientForm.save();
}
newClientForm.unload();
formWin.close();
});

solution :-

var formWin = dhtmlxWin.createWindow(‘formWin’, 0, 0, 320, 240);
//define form
var str = [ … ];
var newClientForm = formWin.attachForm(str);
newClientForm.attachEvent(“onButtonClick”,function(buttonID){
if(buttonID==“save”) {
newClientForm.save();
}

});

newClientForm.attachEvent(“onAfterSave”, function (id, xml){
newClientForm.unload();
formWin.close();
});