Validating form with onHide & showFormInDialog

HI,
I need to validate a record before the user navigates away from it, I have the following working OK, but with one issue

onHide method is:

if(globals.gFormOkToClose == 1){
} else {

application.showFormInDialog(forms.sales_order_details,-1,-1,-1,-1,'Sales Order',false,false,'Sales Order',true); //sets a modal window
return false; //stops the user from closing window with the "red cross" 

}

the above works well, and forces the user to press a save button on the FID, this fires below method

globals.gFormOkToClose = 1 //will allow form to close unless saved/resaved

var vIsFormInDialog = application.isFormInDialog(controller.getName())
if(vIsFormInDialog){
application.closeFormDialog('Sales Order')
}

All this works well, BUT after the FID has closed the user has a grey window, I guess like the original form does not exist anymore. Is there anyway around this, do I need to reload the original form again ??

HI,

I am not getting far fast with a resolution on this problem, I think now there maybe a bug of some sorts with the onHide event in servoy.

It seems to be unreliable one minute working as expected and the next not at all, the odd thing is that it seems to work as expected when the debugger is on??, when I turn debugger off it seems only to fire on every second onHide event.

I am using Servoy version 3.52

my code

onHide on sales orders

if(globals.gFormOkToClose == 1){
} else {
forms.dialog_unsaved_data.popupDialog();
}

popupDialog method

var vFormInDialog = application.isFormInDialog(controller.getName())
if(vFormInDialog){ //close any open dialogs the reopen
application.closeFormDialog('Error')
}
application.showFormInDialog(forms.dialog_unsaved_data,-1,-1,-1,-1,'Error',false,false,'Error',true);

onHide method for popup dialog to stop user closing window

if(globals.gFormOkToClose == 1){
} else {
return false; //stops the user from closing window with the "red cross" 
}

this method is fired from buttons on the popupDialog form

var vElemName = application.getMethodTriggerElementName()

var vFormName = globals.arrSaveDialog[0]
var vSaveMethod = globals.arrSaveDialog[1]
var vDeleteMethod = globals.arrSaveDialog[2]
var vGoBack = globals.arrSaveDialog[3]
var vPk = globals.arrSaveDialog[4]

if(vElemName == 'btn_saveRecord'){//do save
}


if(vElemName == 'btn_deleteRecord'){//do delete
}

if(vElemName == 'btn_goBack'){
forms[vFormName][vGoBack](vPk); //do go back to unsaved record
application.closeFormDialog('Error') //close window after reshowing unsaved form
}

any ideas would be greatly appreciated

Are you showing the same form in your main window and the dialog? Because it is not possible to show the same form twice.

To do what you want, you need to create a new instance of the form using application.createNewFormInstance() and show that in the dialog.