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

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 forma...

Manipulating Images with the... Database?

A recent thread on the OTN HTML DB Forum asked about how to determine the width & height of an image stored as a BLOB in an Oracle table. I mentioned in that thread that I have some code to manipulate an image stored in a BLOB column. This is particularly useful if you’re going to let users upload images, and you want to re-size them to display as a thumbnail. Thanks to Oracle interMedia , it is trivial to manipulate the width, height, and other attributes of images stored in an Oracle table. I’ve created a sample application here which demonstrates Oracle interMedia and HTML DB in action. Feel free to have a look. You can download this application from HTML DB Studio as well. Basically, this application allows you to upload images and perform an operation on the image as it is inserted into the PHOTO_CATALOG table. There are two places where some PL/SQL code is required: an After Submit process on page 2, and a procedure to display the images. Here is the PL/SQL for the After...

Page 0 Branches

What? There's no way to put a Branch on Page 0 of an ApEx application! Or is there... Technically, no - page 0 does not support branches. But how many times do you wish it did? This scenario recently came up: I wanted to put a "Search" box on every page in my application, so no matter where a user is, they can search the site. Currently, it has 10 or so pages, but this will grow to closer to 50 by production. So, thought #1 was to put an text item on Page 0, call it search, and then ensure that each and every page had some sort of Branch to run the search. Not so fun, as this was a tedious task, even for just 10 pages. And each time a new page was added to the application - by myself or anyone else - the search branch would have to be added to the page. Clearly not a scalable solution. With a little bit of help from Raj from the ApEx team, I came up with this solution: Create Page 0, if you haven't already On page 0, create an item of type "Text Field (...