How set a dependent checkbox variable mandatory which is dependent on another checkbox
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 06:44 AM
Hi, I have a requirement
When I select a "requested for/by" as "someone else " checkbox . 4 checkboxes are present in "Please choose the environment"
1. PRD
2.DEV
3.PRE
4.SIT
As mentioned in below screenshot.
When I select PRD, 3 checkboxes should be visible I want to make mandatory any of the three field without selecting any of those three field a user can't proceed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 07:31 AM
Hi,
1. Create a UI policy to show those three checkboxes only when the selected option is PRD.
2. Write an onSubmit client script to check if any of the checkboxes are selected
function onSubmit() {
//Type appropriate comment here, and begin script below
var answer = false;
if (g_form.getValue('environment') == 'PRD') {
if (g_form.getValue('rcp') == 'true' || g_form.getValue('s4p') == 'true' || g_form.getValue('s1p') == 'true') {
answer = true;
} else {
g_form.addErrorMessage('atleast one selection to be made', 'warning'); //your wording goes here
}
}
return answer;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2024 08:00 PM
Hi @Manoj89
Thank you for suggestion, I write this onSubmit client script and it is working.
function onSubmit() {
var prdParentCheckbox = 'prd_production';
var devParentCheckbox = 'dev_development';
var sitParentCheckbox = 'sit_system_integration_test';
var preParentCheckbox = 'pre_preproduction';
//var sitParentCheckbox = 'pre_preproduction';
var requiredChildCheckboxes = ['rcp_100_sap_grc_access_control','s4p_100_backend_prod','s1p_001_sap_solution_manager',
'rcd_100','s4d_100','s4d_200','s4d_201','s4d_202','s4d_400',
's1d_001_sap_solution_manager','rcq_100','rcq_400','s4q_100','s4q_200','s4q_201','s4q_600','s4q_610',
'rcv_100','rcv_400','s4v_100'];
var prdChecked = g_form.getValue(prdParentCheckbox) == 'true';
var devChecked = g_form.getValue(devParentCheckbox) == 'true';
var sitChecked = g_form.getValue(sitParentCheckbox) == 'true';
var preChecked = g_form.getValue(preParentCheckbox) == 'true';
if ((prdChecked && !hasCheckedChildCheckbox(requiredChildCheckboxes.slice(0, 3))) ||
(devChecked && !hasCheckedChildCheckbox(requiredChildCheckboxes.slice(3, 10))) ||
(sitChecked && !hasCheckedChildCheckbox(requiredChildCheckboxes.slice(10, 17)))||
(preChecked && !hasCheckedChildCheckbox(requiredChildCheckboxes.slice(17, 20))))
{
alert('For each selected Environment checkbox, at least one child checkbox must be checked!');
return false; // Prevent form submission
}
return true; // Allow form submission
}
function hasCheckedChildCheckbox(childCheckboxes) {
for (var i = 0; i < childCheckboxes.length; i++) {
if (g_form.getValue(childCheckboxes[i]) == 'true') {
return true;
}
}
return false;
}