How to Show/Hide Fields with Dynamic Actions in Oracle APEX!
Hey APEX adventurers! Ever wanted to make your forms smarter, reacting to user input without writing a single line of JavaScript? That's where Dynamic Actions (DAs) shine! Today, we're diving into a super common, super useful scenario: showing or hiding a "Reason" field based on a "Status" selection. Let's get visual!
Here is a step-by-step walkthrough to create a Dynamic Action that hides/shows a "Reason" field based on a "Status" selection.
Step 1: Create the Triggering Item
First, you need the item that the user will interact with. In this case, we will use a Select List for a Status field.
In the Rendering Tree (left pane), right-click your region and select Create Page Item.
Set the Name to
P1_STATUS.Set the Type to Select List.
Under List of Values, create two static values:
ACTIVEandINACTIVE.
Step 2: Create the Affected Item
This is the item that will react to the change. We want a "Reason" field that only appears when the status is INACTIVE.
Create another item named
P1_REASON.Set the Type to Textarea.
Important: Scroll down to Appearance and set Display Entity to Pre-Text or simply ensure it is visible by default so we can test the "Hide" logic.
Step 3: Define the Dynamic Action (The "When")
Now we tell APEX to watch the Status field.
Right-click
P1_STATUSin the Rendering Tree and select Create Dynamic Action.Name: Give it a clear name like
Hide/Show Reason.When Section:
Event: Change
Selection Type: Item(s)
Item(s):
P1_STATUS
Client-side Condition:
Type: Item = Value
Item:
P1_STATUSValue:
INACTIVE
Step 4: Create the True Action (The "Show")
If the status is INACTIVE (the condition is True), we want to show the field.
Under the True node of your Dynamic Action, click the default action.
Action: Show
Affected Elements:
Selection Type: Item(s)
Item(s):
P1_REASON
Step 5: Create the False Action (The "Hide")
If the status is anything else (the condition is False), we want to hide the field.
Right-click the True Action you just made and select Create Opposite Action.
APEX will automatically create a Hide action under the False node for
P1_REASON.
Step 6: Save and Test
Click the Save button in the top right.
Click the Run icon.
Change the Status dropdown. When you select
INACTIVE, the Reason box should slide into view; when you selectACTIVE, it should disappear.
Pro-Tip: "Fire on Initialization"
By default, the "Show" or "Hide" action might not run when the page first loads. To fix this:
Click on the Show action.
In the Property Editor, toggle Fire on Initialization to On.
This ensures that if the record is already "Active" when you open the page, the "Reason" field starts hidden.
Comments
Post a Comment