Form-level validation rules
Form-level validation rules can be defined for each field controlled by a dialog.
Form-level validation can be specified at the form field level with attributes such as
NOT NULL, REQUIRED and INCLUDE. These
attributes are part of the business rules of the application and must be checked before saving
data into the database.
Implicit validation rule checking
An INPUT or INPUT ARRAY block automatically executes
form-level validation rules in the following cases:
- The
NOT NULLattribute is satisfied if a value is in the field.NOT NULLis checked:- when the user moves to a different row in a list controlled by an
INPUT ARRAY. However, if the row is temporary and none of the fields is touched, the attribute is ignored. - in a
DIALOGblock, when focus leaves the sub-dialog controlling the field. - in a
DIALOGblock, whenNEXT FIELDgives the focus to a field in a different sub-dialog than the current sub-dialog. - when the dialog instruction is ended, for example when a procedural
DIALOGis ended withACCEPT DIALOG, or when an singularINPUTis ended withACCEPT INPUTor with the automatic accept action.
- when the user moves to a different row in a list controlled by an
- The
REQUIREDattribute is satisfied if the field modification flag is true, if aDEFAULTvalue is defined, or if theWITHOUT DEFAULTSoption is used.REQUIREDis checked:- when the user moves to a different row in a list controlled by an
INPUT ARRAY. However, if the row is temporary and none of the fields is touched, the attribute is ignored. - in a
DIALOGblock, when focus leaves the sub-dialog controlling the field. - in a
DIALOGblock, whenNEXT FIELDgives the focus to a field in a different sub-dialog than the current sub-dialog. - when the dialog instruction is ended, for example when a procedural
DIALOGis ended withACCEPT DIALOG, or when a singularINPUTis ended withACCEPT INPUTor with the automatic accept action.
- when the user moves to a different row in a list controlled by an
- The
INCLUDEattribute is satisfied if the value is in the list defined by the attribute.INCLUDEis checked when the target program variable must be assigned. This happens:- when
UNBUFFEREDmode is used, focus is in the field, and an action is invoked. - when the focus leaves the field.
- when the user moves to a different row in a list controlled by an
INPUT ARRAY. However, if the row is temporary and none of the fields is touched, the attribute is ignored. - in a
DIALOGblock, when focus leaves the sub-dialog controlling the field. - in a
DIALOGblock, whenNEXT FIELDgives the focus to a field in a different sub-dialog than the current sub-dialog. - when the dialog instruction is ended, for example when a procedural
DIALOGis ended withACCEPT DIALOG, or when a singularINPUTis ended withACCEPT INPUTor with the automatic accept action.
- when
Performing validation rules explicitly
Singular input dialogs (INPUT / INPUT ARRAY) create
default accept / cancel actions. The form-level validation rules are typically performed when the
accept action is triggered.
The DIALOG procedural instruction can be used as in singular interactive
instructions, with the typical OK / Cancel buttons (accept / cancel actions) to finish the
instruction. The accept/cancel action handlers would respectively execute the ACCEPT
DIALOG and EXIT DIALOG instructions. This solution allows the user to
input or modify one record at a time, and the program flow must reenter theDIALOG
instruction to edit or create another record. Alternatively, theDIALOG instruction
can let the user input / modify multiple records without leaving the dialog. In this case, you need
a way to execute the form-level validation rules defined for each field, before saving the data to
the database.
DIALOG instruction, use the
ui.Dialog.validate("field-list") method, as shown in this
example: ON ACTION save
IF DIALOG.validate("cust.*") < 0 THEN
CONTINUE DIALOG
END IF
CALL customer_save()This method automatically
displays an error message and registers the next field in case of
error. It is mandatory to execute a CONTINUE DIALOG instruction
if the function returns an error.
Within singular input dialogs, form-level validation rules can also be explicitly performed
with the ACCEPT INPUT instruction, or with the
DIALOG.validate("*") API call, followed by a CONTINUE
INPUT in case of error.