Null Display Value on Read-only List Item

The updated Universal Theme has added new “Floating” item templates which look great, e.g.:

I had a list item which I wanted to leave optional; if the user leaves it null, I wanted it to show a “default” display value (derived at runtime). To implement this, I added a hidden item (P10_DEPTNO_DEFAULT) and on the list item set Null Display Value to &P10_DEPTNO_DEFAULT..

If the page is shown in read-only mode, however, the list item is rendered as a Display Item, and the Null Display Value attribute is ignored:

To solve this, I added a Dynamic Action which injects the default value into the HTML for display (without affecting the value of the underlying item):

  • Event: Page Load
  • Server-side Condition: <page is readonly> AND :P10_DEPTNO IS NULL
  • Action: Execute JavaScript Code
  • Fire on Initialization: No
  • Code:

This finds the span for the display-only item and injects the default display value for display:

If you want to see this in action for yourself, here is a demo: https://apex.oracle.com/pls/apex/f?p=APEXTEST:DISPSHOWDEFAULT&c=JK64

Disable scheduler jobs during deployment
Wipe APEX mail queue

Comments

  1. A nice easy solution, but personally, I prefer to add a default value of CASE WHEN THEN ELSE NULL END. That way, you don’t have the possibility of the page loading with a blank value and then it populating.

    • Thanks for the comment Eric, but unfortunately I don’t quite understand what you mean. This item is not supposed to have a default value; the purpose is to load the item with an actual NULL, which is shown using the Null Display Value attribute when the list item is editable. This attribute does not support PL/SQL expressions like CASE, and in any case is ignored if the item is readonly.

Leave a Reply

Your email address will not be published / Required fields are marked *