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
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');
Learn More
- You can learn more helpful tips like the ones above by visiting the Traust Consulting Blog.
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.