Skip to Main Content

Add style to form item with jQuery after validation error

I did see in OTN APEX forum question how to highlight an item based on a validation. I have made the solution earlier for that and discussed topic in other post.

I just wrap up solution now here.

If you are on APEX 3 load jQuery library on your page template header.

Go to Shared Components > Templates and filter report by Type "Label".
Copy your favorite label template to new name and edit it.

Add to "On Error After Label" JavaScript that modify your item. E.g. add jQuery UI error state class:

<script type="text/javascript">
$(function(){
 $("##CURRENT_ITEM_NAME#").addClass("ui-state-error");
});
</script>

Or you can define styles using jQuery css method e.g.:

<script type="text/javascript">
$(function(){
 $("##CURRENT_ITEM_NAME#").css({"font-weight":"bold","background-color":"red"});
});
</script>

Change form items to use your new label template.

Edit:
Marko reminding me that validations Error message display location must be set to "Inline In Field" or "Inline In Field and In Notification"..

Comments

  • Speed99 27 May 2011
    Hi, I was searching for it. Perfect solution. Thanks :D
  • Jari Laine 20 Apr 2011

    Hi Marko,

    Thank you for informing this. I will update post.

    Regards,
    Jari

  • Marko 20 Apr 2011
    You forgot to mention that this will only work if we have display error location set to "Inline In Field" or "Inline In Field and In Notificatio". Br, Marko