trigger loseFocus (Form)

ProcScript module that responds to the form losing focus. It can be used to verify the data to ensure that it is complete or correct.

Declaration: trigger loseFocus
Applies to: Form
Activation: Activated by user actions, after the accept or quit trigger completes successfully.
Default behavior: None
Behavior upon completion: If $status is less than 0, the form does not lose focus.

Description

The loseFocus trigger is typically used to verify the data to ensure that it is complete or correct before the form loses focus.

Caution: Do not change focus using the loseFocus trigger. For example, you should not use ProcScript instructions such as setformfocus or $prompt, display a dialog box, or activate another component instance in this trigger.

Trigger Activation

The loseFocus trigger can be activated in several ways:

  • When a mouse click positions the cursor in another form, before that form gains focus, the loseFocus trigger of the current form is activated.
  • When the accept or quit trigger completes successfully, the loseFocus trigger is activated after the exec operation completes (that is, any code following edit or display).
  • When a setformfocus statement requesting focus for another form is executed, the loseFocus trigger of the current form is activated before focus moves to the new form.

The loseFocus trigger is not activated when the form is left with an exit statement.

Displaying an Error Message

In the following example, FLD1 cannot be empty. The loseFocus trigger is used to define the error message, but should not be used to display the error dialog, because this would change the focus.

trigger loseFocus
if FLD1 = ""
  postmessage $instancename, "DialogShow", "FLD1 must have a value"
endif
end; loseFocus

The postmessage statement causes the receiveMessage trigger to be fired, so you can use this trigger to display the error dialog.

trigger receiveMessage
if ($msgid="DialogShow")
   message/error $msgdata
endif
end ; receiveMessage

Communicating with a Parent Instance

The following example sends a message to the parent form when the current form loses focus:

postmessage $instanceparent,"LOSING FOCUS", $instancename

Related Topics