Andrea Caronello
Andrea Caronello

Reputation: 217

Oracle Apex 5.1 - How to dynamically show/hide the '*' Required symbol on a textfield based on specific condition

I have a page with two items:

So, when the page is loaded the application shows a nice '*' symbol to highligth that a value for the textfield is mandatory.

And here is the problem: I need to hide the '*' symbol when the user select the string 'String choice 1' in the select list, whereas I need to show it again when the user select the string 'String choice 2' in the select list.

In other words, a value for the textfield is required only when the user select 'String choice 2' in the select list item.

In this scenario, since the symbol '*' is not a separate page item for which it's possible to set a "server side condition" hence I don't know how to get this resut.

Can someone help me ? Thank you in advance, Best Regards

Upvotes: 3

Views: 2085

Answers (3)

Joe
Joe

Reputation: 3347

One suggestion is to use the APEX API to set the required property for the text field pragmatically.

Upvotes: 0

eaolson
eaolson

Reputation: 15094

I don't believe there's any built-in way to do this. I've done something similar by:

  1. Create a custom Javascript function that accepts as a parameter the id of an Apex page item. The function locates the label for that item and make whatever style changes are needed to mark it as required/not required.
  2. Create a Dynamic Event in your application, with an event of Change, and your select list as the item that fires the event. The event action will be Execute Javascript and the JS to execute is the function you created in (1).

The style changes in (1) will depend on the exact theme of the Apex template you are using, so I can't be more specific. I think I was using a slightly older one and it involved adding an <img> before the text of the label. Other templates may need to have a class added to the label or something. I think in that case, locating the label for the page item was as simple as using a jQuery selector of #P1_ITEM_LABEL.

All this does is change the style of the label so it indicates to the user that the field is required or not. It does not actually enforce that. You will also want to add a validation that the user has selected a value and make that conditional so it executes when the field is actually required.

Upvotes: 1

Ahamed
Ahamed

Reputation: 312

you can try the below code in dynamic action. Hope this works fine.

$('#P1_TEXT').attr("required", "true");

Upvotes: 1

Related Questions