Expressions in the VALID Field Property
When an operator enters data into a field and then presses TAB (or takes other actions to "leave" that field), the VALID expression for that field is evaluated. If it returns True, the operator can continue to other fields. If the expression returns False, the operator is not allowed to leave the field until a valid entry is made. There are two special "variables" available to you in the expression:
-
Value is the current value in the field when TAB is pressed.
-
oDbf is the database object that holds the values for all the fields in the current record. You will seldom need to reference this, but you can use it to see the value of other fields such as "oDbf:First" to return the value of the First name field, or "if( empty(oDbf:Class), …" to see if the Class field is empty.
As an added benefit, since the VALID expression runs after entry to a field, it gives you the opportunity to take other actions as a result of this new data. In particular, you can use SetField() to make automatic changes to other fields in the window.
SetField() Function
SetField(cField, xValue) sets the value of some other field in the current record.
Following is an example where the Referred By field will get set to BTB if label4 is empty:
if( empty(odbf:label4 ),setfield("referredby","BTB"),.T.)
The if(empty…) statement needs to be input into the valid property for label4. Then, BTB would show up in the Referred By field if label4 is left blank when doing data input.
Iscode() Function
IsCode( lForceListBox, cCodeType )
Where cCodeType identifies the list of codes (usually the name of a field). Pass .t. in the first parameter to display a listbox; pass .F. to use as it in a valid expression.
For example: In the Screen Designer field properties window for a field called "MY_CODE", you would put
IsCode( .T., "MY_CODE" ) in the ListBox setup, and
IsCode( .F., "MY_CODE" ) in the VALID expression
On screen, the field will behave like the WHO code fields where the user can either type a comma-separated list of codes, or click the lookup button to tag codes in a tag-able browse, which will create the comma-separated list to be stored in the field.
InitLabels() Function
The InitLabels() function is called from the valid expression for the Name window first name field. It initializes the label fields according to the option number passed to it:
InitLabels( nMode ): Change the nMode parameter to 1 2 or 3 to affect the first 2 Label fields:
1= Label1 == first+last;
2= Label1 == blank, Label2 == first+last
3= Label1 == first, Label2 == last
Address( , , , nLines ): guarantees minimum number lines output (pads CRLFs so in output to form generation you can guarantee the same number of lines)
IsZip()
IsZip() validates any secondary zip code field and works with different city and state fields as well.
For example, a customer wants to have two have two addresses in a name record.
To implement, add 3 new fields for city/state/zip as in CityHome, StateHome, ZipHome. (Fields can be any legal name, so HomeCity is fine too.)
In the Screen Designer, add the 3 fields, then edit the ZipHome field and set the VALID field to:
IsZip( .F., "CityHome", "StateHome")
and the LISTBOX field to:
IsZip( .T., "CityHome", "StateHome")
The field called ZipHome will be validated just as the original Zip field, and it will set the CityHome and StateHome fields just as the original City and State are by the Zip field.