How to Clear Error Messages from Parent Pages in Oracle APEX Modals
Error messages are key to keeping users informed when working with Oracle APEX applications. However, there are times when you might want to clear error messages from the parent page to ensure the user sees only the messages relevant to their current action within the modal. This approach helps maintain a clean interface and avoids unnecessary distractions.
In this blog, I’ll walk you through how to clear error messages from both parent and modal pages and create a cleaner user experience.
Why Clear Parent Page Error Messages?
Imagine this: A user opens a modal dialog to update some information. The parent page already has error messages displayed from a previous action, but these messages are no longer relevant to the task at hand. Clearing these messages ensures the user is not confused by outdated or irrelevant errors.
The Fix
Oracle APEX provides us with a handy method to clear error messages, and we can prefix that method with the reference to the parent window:
parent.apex.message.clearErrors();
- This clears any error messages from the parent page.apex.message.clearErrors();
- This clears error messages from the current page (the modal).
By using the codes above in the right places, you can ensure your app only shows the necessary error messages where needed.
Steps:
Clear Errors on the Parent Page
Before opening a modal, use
parent.apex.message.clearErrors();
to remove any lingering error messages on the parent page.Clear Errors in the Modal
Useapex.message.clearErrors();
to clear error messages that belong to the modal itself.Combine Both Methods
To cover all bases, combine the two methods when handling validations between modals and parent pages:
The Dynamic Action shown above is an example of how those JavaScript lines of code can be used to clear errors in the parent page and modal.
parent.apex.message.clearErrors(); apex.message.clearErrors();
The above demonstrates a scenario where error messages are cleared from the parent page before interacting with the modal.
In this example, the parent.apex.message.clearErrors(); method is used to remove any outdated or irrelevant error messages on the parent page, ensuring the user sees only the messages related to the current action in the modal. The code provided in this blog can be rearranged to fit any other use cases like clearing messages on the open of a modal.
Tips
Clear error messages thoughtfully to avoid accidentally removing important ones.
Only use
parent.apex.message.clearErrors();
when it’s needed to avoid unexpected behavior on the parent page.
By combining parent.apex.message.clearErrors();
and apex.message.clearErrors();
in your Oracle APEX apps, you can keep error messages tidy and user-friendly. These small changes can make a big difference in creating a seamless experience for your users.