Consultor Eletrônico



Kbase P17806: Why LEAVE trigger data validation is a bad idea
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/16/2008
Status: Verified

GOAL:

Why LEAVE trigger data validation is a bad idea

FIX:

Many programmers attempt to mimic Version 6 field-level validation by using LEAVE triggers in their GUI programs. This is not advised for two reasons.

First, users of event-driven programs have certain expectations about what they will encounter when they use their programs. These expectations are commonly related to the "style rules" obeyed by all applications written for use in that environment.

In native GUI environment this native style rules include a stipulation that an application not prevent navigation out of a widget based upon the contents of that widget.

In other words, validation should be carried out only when a user has signaled readiness by applying some sort of a "Save" event. Event-driven programs by definition presuppose this type of user control. When LEAVE trigger validation is used, an application in effect takes over a vital part of the "Save" event processing and moves it to an inappropriate place.

The resulting behavior -- the insistence that focus remain on a particular
widget until its data requirement is satisfied -- confuses the user with its variance from accepted GUI standards.

Second, the LEAVE trigger becomes a problem when a user decides that he or she wishes to cancel data input altogether. For example, a developer may provide a "Cancel" button on an interface to serve as a mechanism for canceling. However, in order to click on the "Cancel" button, the user must be able to leave whichever field he or she is currently in. The LEAVE trigger prevents this, resulting in a programming paradox: in order to cancel an interaction, the
user must first enter valid data as though the interaction were to be completed. This can be confusing as well -- and frustrating.

For this reason, programmers are strongly discouraged from incorporating LEAVE trigger validation in their event-driven programs. Validation should be carried out using either schema triggers or code that is included within the trigger block of some sort of "Save" construct, such as a "Save" button.

If programmers insist on including LEAVE trigger validation then they should allow the user to bypass the execution of the trigger when the user clicks a "Cancel" button. One way to do that is to design the LEAVE trigger along the following lines:

ON LEAVE OF <SomeWidget>
DO:
IF LAST-EVENT:EVENT-TYPE = "PROGRESS":U AND
LAST-EVENT:WIDGET-ENTER = pbnCancel:HANDLE THEN
RETURN.

/* Normal LEAVE trigger code goes here */
END.