Field validation occurs when the user leaves a field. Validation of the current field does not occur if the user quits the form (i.e., next action code is AC_QUIT). The steps occurring during the field validation process are as follows:
| 1 | The field is checked to see if it needs to be validated by checking the field validation flag. If the field is already validated, if the SKIP option is turned ON, or if the NOVAL_BLANK option is turned on and the field is blank, the validation process stops |
| 2 | If the REQUIRED option is set ON for the field, vf_req() is called to make sure the user entered at least one non-blank character in the field. If the string in the field is all blanks, the test fails and VAL_ERR is set to VAL_ERR:FIELD_REQ and the user is returned to the field. |
| 3 | If the FILL option is set ON, vf_fill() is called to make sure the user put a character in every position in the field. The character can be a space character only if it is between two non-blank characters; thus, embedded blanks are allowed. Leading and trailing blanks are not allowed. If the field fails, VAL_ERR is set to VAL_ERR:NOT_FILLED and the user is returned to the field. |
| 4 | If there is a system validation function for this field type, it is called. Some field types, such as memo fields and pushbuttons, do not have a system validation function. The system validation functions for each field type are listed in Table 32.1. You should refer to the Function Reference for details about the checks these functions make and what validation error codes they can set.
The system validation functions ensure that the string in the field is a valid string representation for a field of that type. After this is done, the system validation function makes sure the value in the field falls within the allowed range for the field, if one is specified. By convention, a validation function returns TRUE if the contents are valid. In this case, the validation process continues. If any of the checks fail, the function sets the global validation error code VAL_ERR and returns FALSE. The validation process stops and the user is returned to the field. |
| 5 | If you have installed a field validation function, it is called. Validation functions that you write and install can do any type of checking you desire on the data entered by the user in a field. If your validation function returns FALSE, the user is returned to the field. |
| 6 | If any of the system validation checks fail, or if your user validation function returns a FALSE value to indicate that it failed, the user is returned to the field. The key processing loop in the form editor then checks VAL_ERR, and if it is not zero, pops up the error window and writes the message associated with the validation error code. For date, time, and Boolean fields, the system also writes the required format or allowed characters for the field immediately after the validation error message. The validation error codes are #defined in vv_form.h and their corresponding messages are defined in vv_valmsg.c. |
The user can then alter the field contents to correct the error.
Table 32.1: System Field Validation Functions
| Field Type | System Validation Function |
| F_BOOL | vf_bool() |
| F_CHAR | vf_ch() |
| F_CHECK | NONE |
| F_DATE | vf_date() |
| F_DECIMAL | vf_dec() |
| F_DOUBLE | vf_double() |
| F_INT | vf_int() |
| F_LONG | vf_long() |
| F_RADIO | NONE |
| F_SHORT | vf_short() |
| F_SINGLE | vf_double() |
| F_STRING | vf_st() |
| F_TIME | vf_time() |
| F_MEMO | NONE |
| F_PUSH | NONE |