Validating Modal Windows

A modal window forces a user to respond to a prompt before continuing execution of a script.  The JMP user interface rarely uses modal windows and as programmers we should respect this principle and use modal windows sparingly.  If a task is important enough to warrant a modal window it’s probably important enough to demand some level of validation of user inputs.  Here’s how:  

Here is a modal dialog, about as simple as it can get:


I’m prompting for a name.  This name might end up being the name of a table, a name of a column, or a data value within a table.

The construction of the above modal window is simple:

It’s important for me that this name is unique.  It’s also important that I don’t have any weird names!


Here’s the problem:

On line 14 I have retrieved the name from the input field.  Once I have that name I can perform some logic to validate the name.  If the name is invalid then I would like to display a message in the tbStatus text box and then retrieve a new name.  However, at line 14 the window has already been closed!

Here’s the solution:

JMP raises a validation event prior to closing the window.  I can implement a handler for this event using the message OnValidate.

Here is an example:

The highlighted rows implement the handler for the OnValidate event.  This event occurs when the user clicks the OK button but whilst the window is still open.  The handler must return a boolean value (retVal) that indicates whether or not the validation has been successful.

Line 3 sets the default to be that validation is successful.  The value of retVal is returned on line 16.  Don’t try using the Return function, it will cause JMP to crash!

Line 5 implements a user-defined test for whether the input name is unique.  If the flag exists is set then line 7 sets the error message and line 8 sets the validation flag to false.  That completes the implementation of the first validation rule.  The second rule is implemented on lines 10 to 14 using pattern matching to identify invalid characters in the input name.

One thought on “Validating Modal Windows”

Leave a Reply

Your email address will not be published. Required fields are marked *