Combining Validations with Dynamic Actions

Matt Mulvaney Mar 1, 2015 8:45:38 AM

APEX has an extensive set of built-in validations to capture every eventuality. They pop up an informative notification message and can direct the user directly to the fault.

Validations, however, only activate when a page is submitted. This is great in almost every case… well… what if you don’t want to submit your page?

For example, your page makes use of dynamic actions to process data (and there are reasons why you’d choose to do this which we won’t go into here). So how do you alert the user when the input data does not validate?

Consider an example:

Within a region, there is a single text item (P1_TEXT_ITEM) and a button (P1_BUTTON). We want a dynamic action on the button so that when the user clicks the button, it inserts the value of the text item to a table. We also need to alert the user when there text item is null. You may have other validations within your application; so you want the user to see consistent looking validation messages.

This blog demonstrates consistency by combining APEX Validations with Dynamic Actions

To Demonstrate this:

  1. Create a hidden page item called P1_VALIDATION_FAILED (protected = No)
  2. Create a Not Null Validation on P1_TEXT_ITEM with a condition of :request = ‘P1_BUTTON’
  3. On your button create a PL/SQL on “Click” True action

PL/SQL Code:

Combining Validations with Dynamic Actions

(Note: If your code is over 4000 characters, there is a workaround on our blog)

Page Items to Submit: p1_text_item

Page Items to Return: p1_validation_failed

Create another True Action, this time a JavaScript action

Fire on page Load = Un-ticked

JavaScript Code

Combining Validations with Dynamic Actions

So what the above is doing is hiding the Error notification message and removing the Label error if you have an error message display location set to “Inline with Field”. These errors will either stay hidden if the page passes validation or reappear is the page fails validation. It then submits the page, firing the validation, if the PL/SQL process failed validation.

If you would like to find out more information speak to one of our Oracle APEX experts, get in touch through enquiries@dsp.co.uk or book a meeting...

Book a Meeting


 

Author: Matt Mulvaney

Job Title: Senior Oracle APEX Development Consultant

Bio: Matt is an experienced APEX solution designer having designed numerous complex systems using a broad range of Oracle Technologies. Building on his previous experience of Oracle Forms & PL/SQL, he is entirely focused on providing functionally rich APEX solutions. Matt promotes APEX as a software platform and openly shares best practises, techniques & approaches. Matt has a passion for excellence and enjoys producing high quality software solutions which provide a real business benefit.