# Validating form with onHide & showFormInDialog

**URL:** <https://forum.servoy.com/t/validating-form-with-onhide-showformindialog/10669>\
**Category:** Classic Servoy\
**Created:** [May 17, 2009, 4:26am UTC](https://forum.servoy.com/t/validating-form-with-onhide-showformindialog/10669 "2009-05-17T04:26:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wvitpr](https://avatars.discourse-cdn.com/v4/letter/w/e0b2c6/32.png) [@wvitpr](https://forum.servoy.com/u/wvitpr)\
**Post date:** [May 17, 2009, 4:26am UTC](https://forum.servoy.com/t/validating-form-with-onhide-showformindialog/10669/1 "2009-05-17T04:26:54Z")

</div>

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:

```auto
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

```auto
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 ??

---

<div class="post-metadata">

**Author:** ![wvitpr](https://avatars.discourse-cdn.com/v4/letter/w/e0b2c6/32.png) [@wvitpr](https://forum.servoy.com/u/wvitpr)\
**Post date:** [May 18, 2009, 1:16pm UTC](https://forum.servoy.com/t/validating-form-with-onhide-showformindialog/10669/2 "2009-05-18T13:16:41Z")

</div>

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

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

```

popupDialog method

```auto
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

```auto
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

```auto
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

---

<div class="post-metadata">

**Author:** ![Joas](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/joas/32/5095_2.png) [@Joas](https://forum.servoy.com/u/Joas)\
**Post date:** [May 18, 2009, 2:45pm UTC](https://forum.servoy.com/t/validating-form-with-onhide-showformindialog/10669/3 "2009-05-18T14:45:03Z")

</div>

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.
