# onFocusGained with showFormInDialog

**URL:** <https://forum.servoy.com/t/onfocusgained-with-showformindialog/2384>\
**Category:** Classic Servoy\
**Created:** [August 2, 2004, 7:52am UTC](https://forum.servoy.com/t/onfocusgained-with-showformindialog/2384 "2004-08-02T07:52:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gert](https://avatars.discourse-cdn.com/v4/letter/g/7bcc69/32.png) [@Gert](https://forum.servoy.com/u/Gert)\
**Post date:** [August 2, 2004, 7:52am UTC](https://forum.servoy.com/t/onfocusgained-with-showformindialog/2384/1 "2004-08-02T07:52:10Z")

</div>

I use the following method in form "smurg1"to call another form in a dialog, to select a value:  
“application.showFormInDialog(forms.Transport,-1,-1,-1,-1);”  
“Transport” is table-view, to select a value, and this method is triggered by “onFocusGain”.  
A button selects the value and closes the dialog with following code:  
“forms.smurg1.nagr = nrvetsiging;  
application.closeFormDialog();”  
with nrvestiging and nagr is a dataprovider.

Every time the the second method, to select the value, is run, the first method runs (this happens only ones) again.

What do I do wrong? Sorry, still beginner with servoy.

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [August 2, 2004, 3:43pm UTC](https://forum.servoy.com/t/onfocusgained-with-showformindialog/2384/2 "2004-08-02T15:43:30Z")

</div>

please send a small example demonstrating this

---

<div class="post-metadata">

**Author:** ![Gert](https://avatars.discourse-cdn.com/v4/letter/g/7bcc69/32.png) [@Gert](https://forum.servoy.com/u/Gert)\
**Post date:** [August 3, 2004, 7:56am UTC](https://forum.servoy.com/t/onfocusgained-with-showformindialog/2384/3 "2004-08-03T07:56:48Z")

</div>

I’m not able to upload an example from here. I’l try again tonight.

Gert

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [August 6, 2004, 12:27pm UTC](https://forum.servoy.com/t/onfocusgained-with-showformindialog/2384/4 "2004-08-06T12:27:15Z")

</div>

the problem is that when you are closing the formDialog, the textfield get’s the focus again and it fires openDialog again. The strange thing is why it doesn’t do that a third time!

To fix this you have to transfer the focus first to another element before calling show form in dialog

i placed a extra button on the form and do now something like this:

```auto
elements.bt.requestFocus()
application.showFormInDialog( forms.test2, -1, -1, -1, -1,"Choose your preference")

```

---

<div class="post-metadata">

**Author:** ![Gert](https://avatars.discourse-cdn.com/v4/letter/g/7bcc69/32.png) [@Gert](https://forum.servoy.com/u/Gert)\
**Post date:** [August 12, 2004, 3:17pm UTC](https://forum.servoy.com/t/onfocusgained-with-showformindialog/2384/5 "2004-08-12T15:17:45Z")

</div>

Thanks for your help Johan!

Gert
