Skip to main content
This blog will show you how to implement read-only and disabled switch widgets in Oracle APEX.  Unlike other page items, the switch widget is more tricky because it transforms when it is read-only and has a built-in validation that can be frustrating to work with.
[su_spacer size=”30″]

Examples

There are multiple ways to display a switch widget as read-only or disabled.  We will examine the main iterations below:

1.)  Read-Only Set to Always

    • Transforms from the default switch widget to text that reads “On” or “Off”
    • Not the most user-friendly
    • Not the most intuitive because the default values are “Y” and “N”
    • This will throw an error on page submit unless you change the page item settings for the switch widget

[su_spacer size=”30″]

2.)  Dynamic Action – Disabled

    • The switch widget displays as normal, but it is grayed out
    • Disabled items cannot hold a value in session state
    • This will throw an error on page submit

[su_spacer size=”30″]

The Best Solution – Dynamic Action JavaScript

  • The widget looks disabled, but still holds a value in session state
  • There are no errors on page submit
  • Create a Dynamic Action on Page Load and use this JavaScript:

$("#P2_SWITCH_ITEM").parent(".a-Switch").addClass("apex_disabled").attr('tabindex','-1');

[su_spacer size=”30″]

Learn More

[su_spacer size=”30″]

Disclaimer:
We do not take responsibility for any unintended or unwanted consequences in your instance of Oracle, Oracle APEX, or related products as a result of reading our blogs or following our guides. Though the information is fully tested and generally safe to use, our lawyers really have a thing against admitting potential wrongdoing. If it makes you feel any better, one time I convinced them that the reason The Matrix broke so many box office records was because it accurately portrayed how real-world hacking was done.  I then told them that it is no coincidence that hacking attacks have grown exponentially since it was released.

[su_spacer size=”30″]
Andrew Schultz, Oracle Developer & APEX Specialist
+ posts

Andrew is a Senior Oracle Application Express (APEX) developer with more than 10 years of experience leading projects from inception to completion. He has built and maintained more than 750 Oracle APEX forms and reports. His prior work as a technical writer and client educator has uniquely prepared Andrew to identify the needs of a task from the perspectives of the organization, programmer, client, and end-user.