This section discusses a special re-definition of the default Exit Form functionality. This can be a requirement when the user tries to exit with pending data block changes, and the form should first prompt for saving these changes and then validate the changes if the response to the first prompt is a Yes. This goes in conformity with the dictum, "Validate only if you want to save changes, otherwise exit 'cool-ly'."
The default behavior of KEY-EXIT or EXIT_FORM is to first perform validation and, if successful, prompt for COMMIT, as shown in Figure 8.1. Specifying ASK_COMMIT, NO_COMMIT, DO_COMMIT, or NO_VALIDATE does not achieve our goal.
Figure 8.1. The Save dialog while exiting a form after successful validation.
If validation is a failure, KEY-EXIT or EXIT_FORM throws up another dialog to close the form, as shown in Figure 8.2.
Figure 8.2. The Close dialog while exiting a form after validation failure.
A better way is to prompt for COMMIT and when the user answers Yes to this dialog, validate. Why should it validate when the user doesn't want to commit? This way the functionality of KEY-EXIT or EXIT_FORM is enhanced over the default functionality.
To use this technique, you can re-define KEY-EXIT as follows :
DECLARE alert_button number; BEGIN /* Initially turn off the validation to avpid forms from validating by default */ SET_FORM_PROPERTY(:SYSTEM.CURRENT_FORM, VALIDATION, PROPERTY_FALSE); ENTER; --- This is required to mark form_success as changed. This will not validate as VALIDATION is turned off. /* Prompt for save if form status is changed */ if :system.form_status = 'CHANGED'then alert_button := show_alert('alert1'); /* If the user responds to above prompt as Yes, turn on validation and initiate it at form scope. */ if alert_button = ALERT_BUTTON1 then SET_FORM_PROPERTY(:SYSTEM.CURRENT_FORM, VALIDATION, PROPERTY_TRUE); VALIDATE(FORM_SCOPE); if form_success then exit_form(do_commit); END IF; /* if the user response is a 'No', exit the form without validating */ elsif alert_button = ALERT_BUTTON2 then exit_form(no_validate); ELSE null; END IF; /* if form status is not changed, simply exit the form */ ELSE exit_form; END IF; END;
Advanced GUI Development: Developing Beyond GUI
Advanced Forms Programming
Object-oriented Methods in Forms
Intelligence in Forms
Additional Interesting Techniques
Working with Trees
Oracle 8 and 8i Features in Forms Developer