Enhancing the Function of Exit Form

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.

graphics/08fig01.gif

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.

graphics/08fig02.gif

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
graphics/ccc.gif
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;




Oracle Developer Forms Techniques
Oracle Developer Forms Techniques
ISBN: 0672318466
EAN: 2147483647
Year: 2005
Pages: 115
Simiral book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net