Combining Validations with Dynamic Actions

Combining Validations with Dynamic Actions

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 in to 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:

(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

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.

 

Facebook
Google+
http://www.explorer.uk.com/combining-validations-dynamic-actions/">
Twitter
LinkedIn

Follow us on twitter

@Explorerukltd

About the Author

Matt Mulvaney

Senior Oracle APEX Development Consultant

Explorer (UK) Ltd – Oracle awarding winning Platinum Partner and UKOUG Database Partner of the year 2015

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.

Explorer, How to / Dynamic Actions

Featured Posts