Skip to main content

Customizing Validation Error Messages

APEX validations allow a server-side validation to occur for a number of different conditions - item not null, item is numeric/alphanumeric, regular expressions, etc. When a validation fails, you have four options to display the corresponding error message:
  1. Inline with Field
  2. Notification Message
  3. Both inline with field & Notification Message
  4. Separate Error Page
With a simple template modification, you can create a fifth option, which is a variation of option #3 above. It will still display the message in the notification, but only highlight the label of the item in question.

This allows for a couple of things: first, if you have a form with a number of items and a fixed width template, error messages inline with items will wreak havoc on the layout, pushing items off to the right and misalign your entire page. By only highlighting the label of the item in question, the user is aware of where the issue is, and can simply look in the notification region to understand what needs to be done to correct the issue.

Here's a screenshot of a page with three items that have NOT NULL validations associated with them. The label template denotes that each of these fields are NOT NULL with the "*" prefix.


And when the page is submitted without any values, here is the result:

Notice that no error messages are displayed inline; only the labels are highlighted in a pink color, denoting that there is an issue with each one. Reading the notification will explain what each of the issues are and potentially offer advise on how to correct them.

This trick is achieved with a simple modification to the Required Label Template that you are using on your page. The changes are quite simple; all that needs to be modified is the Error Display section, as illustrated below:

In this example, I simply added a style tag (style="background-color:#ffa0a7;")to the On Error Before Label attribute. This is what changes the background color to pink for a specific label. You can add any additional attributes here to do whatever you would like to.

Just as important as what was added is what was removed. The token for the actual error message - #ERROR_MESSAGE# - was removed from the On Error After Label attribute. Thus, when APEX renders an item with this Error Template, the only thing that changes is the background color; the Error Message is not added.

Comments

Tony said…
Does this type of error notification still meet ADA?
Scott said…
Tony,

I'm not sure, as it does remove the message inline from the field. You can use other things besides color - for instance, prefix the label with a character - if that is your concern.

Hope this helps,

- Scott -
Jay said…
Scott,

How to i achieve the same for client-side(Application) custom validation errors.
Scott said…
Jay,

Not sure what you mean by that - are you referring to JavaScript validations?

Thanks,

- Scott -
Jay said…
Scott,

I am referring to CONDITIONAL VALIDATIONS under Page_Processing. I am able to show error messages but not able to highlight the label, is there a way to do this?

Thanks
Jay

Popular posts from this blog

Logging APEX Report Downloads

A customer recently asked how APEX could track who clicked “download” from an Interactive Grid.  After some quick searching of the logs, I realized that APEX simply does not record this type of activity, aside from a simple page view type of “AJAX” entry.  This was not specific enough, and of course, led to the next question - can we prevent users from downloading data from a grid entirely?

I knew that any Javascript-based solution would fall short of their security requirements, since it is trivial to reconstruct the URL pattern required to initiate a download, even if the Javascript had removed the option from the menu.  Thus, I had to consider a PL/SQL-based approach - one that could not be bypassed by a malicious end user.

To solve this problem, I turned to APEX’s Initialization PL/SQL Code parameter.  Any PL/SQL code entered in this region will be executed before any other APEX-related process.  Thus, it is literally the first place that a developer can interact with an APEX page…

Thanks, ODC (Oracle Developer Community)!

I owe a lot of thanks to the ODC - which stands for Oracle Developer Community.  What is ODC?  You may remember it as OTN, or the Oracle Technology Network.  Same people, different name.  Why they changed it I can't say.  People just liked it better that way... (love that song)

In any case, what am I thankful for?  A lot.  To start, the tools that I use day in and day out: SQL Developer, ORDS, Oracle Data Modeler, SQLcl and - of course - APEX.  Without these tools, I'm likely on a completely different career path, perhaps even one that aligns more closely with my degree in television management.

While the tools are great, it's really the people that make up the community that make ODC stand out. From the folks who run ODC and the Oracle ACE program to the developers and product managers who are behind the awesome tools, the ODC community is one of, if not the greatest asset of being involved with Oracle's products.

If you have yet to get more involved with this communi…

Custom Export to CSV

It's been a while since I've updated my blog. I've been quite busy lately, and just have not had the time that I used to. We're expecting our 1st child in just a few short weeks now, so most of my free time has been spent learning Lamaze breathing, making the weekly run to Babies R Us, and relocating my office from the larger room upstairs to the smaller one downstairs - which I do happen to like MUCH more than I had anticipated. I have everything I need within a short walk - a bathroom, beer fridge, and 52" HD TV. I only need to go upstairs to eat and sleep now, but alas, this will all change soon...

Recently, I was asked if you could change the way Export to CSV in ApEx works. The short answer is, of course, no. But it's not too difficult to "roll your own" CSV export procedure.

Why would you want to do this? Well, the customer's requirement was to manipulate some data when the Export link was clicked, and then export it to CSV in a format…