Skip to Main Content

Warn on Unsaved Changes

Info

This bug occurs on Apex 21.2.10, but it has been fixed in 23.2.4 (or somewhere in between).

The "Warn on Unsaved Changes" option in Apex is very useful to prevent a user from losing data they enter on a page.
From the built-in Help: "Specify if the user is warned when trying to navigate away from the page, where the page contains unsaved changes. Page Items and Buttons also offer more granular control over when this check is performed, and what is included in it. For Buttons, you can specify if clicking the button will perform the check. For Page Items, you can specify if changes to the item are included, or ignored by the check (see the Warn on Unsaved Changes attribute for both).
Note: This does not apply to an end user closing a Modal dialog page."


However, in older Apex versions it may not always behave as you expect.
In this example, try changing item 1 manually and then click "Home" (to navigate to another page). Your browser will show you a warning.
Then click "Reset", and click "Fill with Set Value", and then click "Home". Same result, your browser will show you a warning.
Finally, click "Reset", and click "Fill with Modal Dialog", select a value from the select list (which closes the modal dialog), and then click "Home". This time your browser will NOT show you a warning.

As stated above, you will not see the bug on this site because I'm running a newer Apex version.
To see the bug in action, rebuild this page in Apex 21.2.10 (or older versions, no idea when this was introduced or fixed).

Some links with related info:
https://forums.oracle.com/ords/apexds/post/cancel-button-on-modal-page-warn-on-unsaved-changes-5114
https://zerointegration.com/apex/oracle-apex-warn-unsaved-changes-for-custom-fields/
https://forums.oracle.com/ords/apexds/post/issue-with-warn-on-unsaved-changes-8718
https://docs.oracle.com/en/database/oracle/apex/23.2/aexjs/apex.page.html#.warnOnUnsavedChanges
https://gist.github.com/hhudson/c2d57dcbdbbc7e01021aada718fe4506#file-apex-detect-changed-items-js

Some JavaScript to find all page items that would trigger the warning (if all the Page and Button "Warn on Unsaved Changes" settings are correct) - run this in the browser console:

Code

Page

Identification
Page ID
Name
Page Alias
Navigation
Warn on Unsaved Changes

Item

Identification
Sequence
Name
Display As
User Interface
Region
Advanced
Warn on Unsaved Changes

Button

Name
Button Name
Text Label / Alt
Displayed
Sequence
Display in Region
Behavior
Action
Execute Validations

Button

Name
Button Name
Text Label / Alt
Displayed
Sequence
Display in Region
Behavior
Action
Target (Redirect URL)
Execute Validations

Dynamic Action

Identification
Name
Execution Options
Sequence
When
Event
Selection Type
Button
Advanced
Event Scope
True Action
Identification
Action
Settings
Set Type
PL/SQL Expression
Escape Special Characters
Suppress Change Event
Execution Options
Sequence
Fire On Initialization
Affected Elements
Selection Type
Item(s)

Dynamic Action

Identification
Name
Execution Options
Sequence
When
Event
Selection Type
Button
Advanced
Event Scope
True Action
Identification
Action
Settings
Set Type
Return Item
Suppress Change Event
Execution Options
Sequence
Fire On Initialization
Affected Elements
Selection Type
Item(s)

Item

Note: This object is located on page 1180
Identification
Sequence
Name
Display As
User Interface
Region
Advanced
Warn on Unsaved Changes

Dynamic Action

Note: This object is located on page 1180
Identification
Name
Execution Options
Sequence
When
Event
Selection Type
Item(s)
Advanced
Event Scope
True Action
Identification
Action
Settings
Items to Return
Execution Options
Sequence
Fire On Initialization