Hack #24. Confirm Record Updates Before Saving

Give users a chance to review their edits before they save a record.

When you're working on a bound form, as you scroll through records, data changes are saved automatically. This behavior is normal and is often appreciated rather than questioned. However, sometimes it is prudent to interrupt this process and let a user review her work. Once the update happens, the original data is gone, unless other measures, such as backups, are in place.

One thing that works in our favor to control this is the Before Update event. By hooking into this event, you can ask the user whether she wants to complete the update. If the answer is no, you undo the changes.

Users should control whether they want to be prompted to confirm changes because the prompts can become annoying. A user might want this feature sometimes but not other times. Figure 3-20 shows a form with a checkbox in the upper-right section that acts as a flag indicating whether to confirm updates.

A checkbox to indicate whether to confirm updates

Figure 3-20. A checkbox to indicate whether to confirm updates

The Before Update event fires only when the data changes. In the event, the checkbox value is tested, and if the value is true, the user is prompted. Figure 3-21 shows the prompt.

If the user clicks Yes, the update proceeds. If she clicks No, an undo command runs, thereby dropping the changes to the data. Here is the event and the code: ...

Get Access Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.