Problem
How do I make a field on a popup modal required/optional based upon a parameter passed from the calling form?
Resolved
Thanks to Jariola and InoL for the help.
In the end, I added a CSS Inline property called required-indicator to the modal form, as shown below:
.required-indicator::before { content: "* "; color: red; }
I then created a Page Load Dynamic Action, as follows:
var workerTypeItem = apex.item('P10_WORKER_TYPE');
var workerShiftElement = document.querySelector("label[for='P10_WORKER_SHIFT']");
if (workerTypeItem.getValue() === 'WORKER')
{
workerShiftElement.classList.add('required-indicator');
$("#P10_WORKER_SHIFT").attr("required", true);
}
else
{
workerShiftElement.classList.remove('required-indicator');
$("#P10_WORKER_SHIFT").attr("required", false);
}
When the page loads, if the Worker Type is “WORKER” then the Worker Shift gets set to “required” and a red (*) is displayed. Otherwise, the field is made optional and the indicator is not presented.
Background
I have a calling form (Page 8) (Workers) with five fields:
WORKER_ID
WORKER_LAST_NAME
WORKER_FIRST_NAME
WORKER_SHIFT
WORKER_TYPE
It is bound to a query and has a body that displays all five fields in a interactive report format.
On the Worker region, I have the Attributes Link section set to call (Page 10) (Workers Editor) and pass all five fields to the modal dialog that has the following controls:
P10_WORKER_ID
P10_WORKER_LAST_NAME
P10_WORKER_FIRST_NAME
P10_WORKER_SHIFT
P10_WORKER_TYPE
So, in the Link Target it maps P10_WORKER_ID to #WORKER_ID, etc. When I load the form using the “edit” icon in the row, it properly launches the dialog, passes the values and fills in the values on the modal dialog.
What I want to do is “on load” look at the WORKER_TYPE from the calling page and then set the P10_WORKER_SHIFT to either required or optional based on the value. If they are a worker, the shift should be required. Otherwise, the shift should be optional.
I tried using a Page Load Dynamic Action to do the following:
var workerTypeValue = $v('WORKER_TYPE');
var workerTypeItem = apex.item('P10_WORKER_SHIFT');
if (workerTypeValue === 'WORKER')
{
workerTypeItem.setRequired(true);
}
else
{
workerTypeItem.setRequired(false);
}
However, the modal just sits there and spins until it times out.
As a troubleshooting activity, I tried hard coding the script to set the P10_WORKER_SHIFT to required, just in case my references back to the calling form were done incorrectly. Same thing. The page never loads.
var workerTypeItem = apex.item('P10_WORKER_SHIFT');
workerTypeItem.setRequired(true);
Any ideas?
Rob