Language Reference Guide : 5. Events : Validate Event
 
Share this page                  
Validate Event
The Validate event is triggered when the user changes the value in a field with a bias of FB_CHANGEABLE.
This event has the following syntax:
on validate [fieldname]
The following attributes of the FrameExec class can be used in the Validate event block:
TriggerField
Specifies the field that has been changed
OriginatorField
Specifies the field specified in the initial on validate statement.
For this event, the values in TriggerField and OriginatorField are the same.
Use the CurFrame system variable to access these attributes. For more information, see FrameExec Class.
Usage: The Validate event is defined for all scalar fields that support SetValue events, and menu toggles and menu lists. This event is not defined for menu groups, shape fields, or composite fields. If you specify this event in a field script, the field name is optional.
For entry fields (as well as free trim and box trim), the event is deferred until the user tries to leave the field or clicks another field or menu item with a FocusBehavior setting of FT_SETVALUE, FT_TAKEFOCUS, or FT_TABTO.
The Validate event provides a way to ensure that valid data is entered in a field. Its most common use is in conjunction with entry fields, to validate the data in the field if the user has changed the existing data or entered new data.
In the following example, the Validate event checks that the user enters a valid value of department:
initialize(dept_in_database = varchar(100) with
null)
...
on validate department =
begin
dept_in_database = null;
repeated select :dept_in_database = dept
from department_table
where dept = :department;
if dept_in_database is null then
CurFrame.InfoPopup(
messagetext = 'Bad department value ' +
department,
messagetype = MT_ERROR);
resume;
endif;
end
Because entry fields accept such a wide variety of data, there is no efficient way for the system to determine when the user actually changes data in them or merely retypes the same data. Consequently, OpenROAD triggers a Validate event when the user types in the field, regardless of whether the user actually changes the data. Conversely, OpenROAD can determine when the user changes a selection in an enumerated field (RadioField, OptionField, or ListField) or menu list, so a Validate event block defined for one of these executes only when the user actually changes the value in the field.
If the Validate event block executes a resume statement, the input focus remains in the current field and any events defined for the next field or the clicked field are not executed.
In some cases, you might want to give the user the option of leaving an entry field without executing a Validate event block defined for the field. You can do so by providing a field, such as a Cancel button, that has a FocusBehavior setting of FT_NOSETVALUE. Fields with this setting do not take the input focus, are not part of the tabbing sequence, and do not force Validate event processing. Of course, you must provide an event block for the button that actually performs whatever operations you do want to perform with the Cancel button (such as closing the frame or setting fields to default values).
If you specify both a SetValue event and a Validate event for a field, the Validate event is processed first.
More information:
OriginatorField Attribute
TriggerField Attribute