A user can close a window by clicking the OK or Cancel button or by clicking the red Close button in the top corner of the window. A message can also be sent to close the window. On Validate and On Close expressions determine what happens you interact with the window.
•
|
On Validate evaluates its expression when the OK button is clicked. The expression is not evaluated for any other button click or action. If the expression evaluates as true, the window closes. If the expression evaluates as false, the window is not closed. The script for an OK button runs when you click the button, no matter what the On Validate expression does.
|
•
|
On Close evaluates its expression right before the window closes. The On Close return value is like the On Validate return value and can prevent the window from closing. However, the best practice for On Close is to always return 1 so that you do not accidentally create a window that cannot be closed.
|
If the window closes, On Close is evaluated. On Close is not evaluated if the On Validate expression returns false, because the window is not closed.
•
|
On Close works for modal or non-modal windows. On Validate works only for modal windows.
|
•
|
Do not use On Close for validation because it does not distinguish between OK and Cancel. Use On Close to clean up resources (such as invisible data tables) because it always runs when the window closes.
|
•
|
Do not use On Validate to clean up resources. Use On Close instead or in addition to On Validate, because On Validate does not run for the Cancel button or red Close button.
|
Suppose that a non-modal window is a report window, and the resource that needs cleaning up is an invisible data table. The On Close script closes the data table. This is good because the user might not know that the data table is open and has no easy way to close it.
dt << Bivariate(
<<Modal,
<<Return Result,
<<On Validate(
tb << Set Text(
New Window( "Modal Window",
<<Modal,