OnObjectExit – Keeping focussed on the field being validated

I use OnObjectExit quite a lot for field validation – “if the field contains x, tell the user it’s not valid and invite  them to enter something else” – but I found that, even if I put a “Go To Field” script step at the end of the script, the cursor didn’t get put in the field (or at least it did, but only until the script finished, at which point the field was no longer the active field).  And it’s not as if control had gone elsewhere – the data viewer confirmed that no field was active once the script had completed.

So a script like this:

If [test::field]  ≠ “2”
Show Custom Dialog [“Not correct”]
Clear [Select;[test::field]
Go to Field [test::field]
End If

doesn’t provide the functionality that I need.  The Go to Field works fine, but once the script ends (with a default result of “true”), control has already gone from “field”.

The solution is to exit the script with a false result.  If the OnObjectExit script finishes with a false result, control remains with the recently exited field.  So instead of the “Go to Field” step, pop in an “Exit script” with a “false” result, and all will be well.

If [test::field]  ≠ “2”
Show Custom Dialog [“Not correct”]
Clear [Select;[test::field]
Exit script [Result: 0]
End If


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s