trigger script when user closes showFormInDialog

Hi,

In my solution, I use these showFormInDialog boxes to prompt for badge ID entry. However, i don’t want the user to just click the “X” on the upper right hand corner and just close the dialog box. How do i force them NOT to close that window using the “X”?

I tried the onHide trigger but that will trigger everytime the form is not in display.

code used to open form

application.showFormInDialog(forms.entry_ng_diam, -1, -1, -1, -1);

thanks!

Hi Sammy,

Set a global just before opening the dialog:

globals.okToClose = 0;
application.showFormInDialog( xxxx......);

Then - have an onClose method:

if (globals.okToClose == 1)
{
  application.closeFormDialog(true);
}
else
{
  return false;
}

Finally - on your close button make sure you include:

globals.okToClose = 1

Hope this points you in the right direction.

Hi Bob,

I’m not sure I understand. I don’t have a “close” button. But when you do a formInDialog, users can press that “X” on the upper right hand corner to close out that dialog box. I need a way to stop the users from just clicking on that button.

There isn’t a “onClose” method for Forms is there? I’m just not sure how I would even trigger this script to run. I need it triggered when the user tries to press the “X” close window Windows button on the upper right hand corner of the dialog box.

thanks

What you should do is use Bob’s suggested ‘onClose’ method at the ‘onHide’ event of the window.

However, using this is potentially dangerous if you don’t have anything for the user to intentionally close the window.

By using the method ALL a user tries to close the window fails unless your global ‘globals.okToClose’ is set to 1.

So I would include a ‘close’, ‘ok’, ‘cancel’ and/or whatever button to the window.

oh okay! i get it now. i’ll try it out. Sorry, i must have had a brain freeze!

thanks for clearing that up IT2BE!

Hi Guys,

could it be that this logic is broke in Servoy 2.2.3. It worked fine before… :cry:

Grtz
Jos.

Are you sure?

Not working in Developer with the debugger on?

Hi Marcel,

nope. Doesn’t work, debugger on or of…

Grtz
Jos

Can’t confirm, haven’t downloaded 2.2.3 yet…

Marcel,

perhaps it’s wise to wait… :wink:

Grtz
Jos

i just tried it with these 2 scripts:

open dialog script:

x= 0;
application.showFormInDialog( forms.addresses)

then the onHide script:

application.output(“onhide”);
x++;
return x == 2;

then the onHide is called and i have to press the close button twice to close the dialog (as i want to)

Johan,

i do the following:

onShow:

lClose = false;

onHide:

if (lClose == false)
{
plugins.Mydialogs.showDebugDialog(‘mooi nie’);
return false;
}

The dialogbox shows when you try to close the dialog with the X button but the dialog closes itsself anyway…

Grtz
Jos

as a big warning: you shouldn’t do this:

if (globals.okToClose == 1)
{
  application.closeFormDialog(true);
}
else
{
  return false;
}

in an onhide method of a form that is shown in the dialog!!
you should just return true or false.
don’t close the dialog because you are in closing the dialog…

johan

Johan,

I understand your warning, how ever, it does not apply to my case (see code above). The only thing i do on hide is show a debug dialog (which is shown!!!) and return false. But the screen doesn’t react to the return value…

Grtz
Jos

Johan,

I’ve created a small sample solution to test this problem and the problem is located somewhere else. In our real life solution we frequently use variables without prefixing them with ‘var’, for example onload of a form. This way they become globals. This comes in handy when defining globals you really don’t want to be in the list of Servoy globals or when defining global arrays. When I use such a variable things go wrong (servoy says the variable is not defined). When I use a real full blooded Servoy global variable it works fine. But the fake ‘global variables’ worked fine up untill now… Has something changed on your side?

Grtz
Jos

You just have the debugger enabled (as marcel already said)

Then that will happen because the dialog is not modal.

Johan,

nope. The debugger is disabled. The sample solution is enclosed here. I’ve commented out the code where i use the fake global so now it works fine. Just decomment it and see the error…

Grtz
Jos.

Jos, what happens when you prefix them with ‘globals.’.

This is how I do that and that works fine (at least pre 2.2.3 :) )

Marcel,

see my comment above.

Grtz
Jos.

Jos,

downloaded 2.2.3 and tested it. IT WORKS…

Also when I don’t use a global.

BTW nice that you evaluate a variable (==) where you want to set it (=). See your onshow :wink: