I have some code that checks values on a form during the onHide event. If the check fails, I want to display a message to the user and then stop the form from closing. I have the message part working, but is it possible to stop the form from closing?
Just add a
return false;
at the point where you want to “stop the closing”…
Well… return false; stops the window from closing – but the problem is once that happens, and the user then fixes the problem and again tries to close the window, the onHide event does not fire and the window just stays open – and I couldn’t figure out any way to close it other then by killing the whole application in the task manager.
Any idea what I can do about this?
The code for the onHide event follows:
var myAssignment = forms.people_assignments.id_assignments
var myTest = globals.DLookup("TempID", "Temp_Assignment_Answers", "id_assignments = " + myAssignment + " And Answer > '' And id_questions is null")
if (myTest == null) {
var iArray = new Array(3);
var argArray = new Array(3);
iArray[0] = 0;
iArray[1] = 0;
iArray[2] = 0;
argArray[0] = globals.id_assignments
argArray[1] = globals.id_projects
argArray[2] = globals.id_form_guides
databaseManager.executeStoredProcedure(currentcontroller.getServerName(),'{call spAssignmentAnswers2(?,?,?)}',argArray,iArray,200)
return true;
}
else {
plugins.dialogs.showErrorDialog("Please Select Needed Questions", "There are answer values which do not have a question selected.")
return false;
}
you can set a (global) variable that is set to true when you want the window to close and false if not. In your onhide method you now dow a check:
if (!trigger) {
return false;
}
Cheers
Marcel,
But its in the onHide method that I need to do the check. Is there some other method that gets fired when the user closes a form that I can do the check and then just have the code as you suggest in the onHide method?
Or am I missing something…?
No, there’s just one event that gets fired when you hide the form. But you say that if the check fails you want to present the user with a dialog.
In your case you present the user with a dialog when myTest holds a value… Is that correct?
Does the test give the result you expect (application.output(myTest);
The test works fine the first time.
If myTest is null, the form is closed and everything is fine.
If myTest is not null, the error message is displayed and the form is not closed. Thats fine. But after that, there doesn’t seem to be a way to close the form at all. If the user clicks to close the form, the onHide method doesn’t display a message and doesn’t seem to run at all (I put a message as the first line in the method to test this and it never).
So, my question is, once I stop a form from closing, what can be done to get it to close again?
Hi Glenn,
Can you first try if this very basic script works?
if(myField == "abc")
{
plugins.dialogs.showErrorDialog( "ValidationError", "value abc is not allowed", "OK")
return false;
}
Does the form ,where the onHide script is attached to,
contain any TABpanels based on a self join relation?
I replace all of the code in the onHide event with:
myVal = globals.retVal
if (myVal == "Open")
{
plugins.dialogs.showErrorDialog( "Validation Error", "value is not allowed", "OK")
return false;
}
and I still get the same result.
The form with the onHide does not have any tab panels.
I can make a sample for you if you want…[/code]
I have found that the problem seems to be related to if the form that the popup is opened from is itself a dialog window or a main form.
The form with the onHide event on it is called assignment_answers. The form which it pops up from is called people_assignments.
If I open people_assignments as the main form and then popup assignment_answers everything is fine. BUT, if I popup people_assignments from the panel_members main form, thats when I get the problem.
Hi Glenn,
Can you send me a sample solution?
Thanks.
I just sent you a sample.
Thanks for your help!!!
thx.
That was a bug, fixed in the next version 2.2rc3