How to make Checkbox selection mandatory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2024 12:12 PM - edited ‎05-22-2024 12:33 PM
Hello,
Requirement is to have at least one or more selected before submitting form. How can I make this Catalog Item checkboxes mandatory.
"Required Provision" is a container so can't be made required.
"Please select:" is a label, and if I make the first option Mandatory then it conflicts with a UI Policy where if the last option is selected, every option above goes read-only. Same for the first option, if it is selected everything below gets read only. (pasted below) The right side of this container is reserved for other fields that pops depending on selection of one of these fields. Please help. Is this going to be a Catalog Client Script?
I have tried below Catalog Client Script but even after selecting one checkbox, its not letting me submit the form. What's wrong with this approach?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2024 12:48 PM
Hi @Snow Angel ,
I tried your script in my PDI and make some changes and it works for me please check below script
function onSubmit() {
//Type appropriate comment here, and begin script below
var checkbox1 = g_form.getValue('check_option_one');
var checkbox2 = g_form.getValue('check_option_two');
var checkbox3 = g_form.getValue('check_option_three');
var checkbox4 = g_form.getValue('check_option_four');
alert("1 = " + checkbox1 + " 2 = " + checkbox2 + " 3 = " + checkbox3 + " 4 = " + checkbox4)
if (checkbox1 == 'false' && checkbox2 == 'false' && checkbox3 == 'false' && checkbox4 == 'false') { // getValue returns value in string so this is a reason I give values in string "false"
alert("Here inside if");
g_form.addErrorMessage("Please select at least 1 choice under Required Provisioning section");
return false; // Prevent form submission if no checkboxes are selected
}
return true; // Allow form submission if at least one checkbox is selected
}
Please change variable name as per your requirments
Result
When I didn't select any value
When I select one or more value
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2024 01:06 PM
Hi @Snow Angel ,
Did you try the option Selection required ? which is available OOTB no need for scripting you can make selection required for any of the checkbox in the sequence so if anyone one is selected it allow you to submit
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2024 01:31 PM
Won't each checkbox would become required then?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2024 02:39 PM - edited ‎05-22-2024 02:45 PM
@Snow Angel nope make any one of the 'checkbox' selection required it will make the label as mandatory so if any of checkbox(one or more) is selected it will allow you to submit
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang