Make a selection mandatory for atleast one checkbox to be selected on a form with alert if nothing selected

Terry Carter Jr
Tera Contributor

Hello everyone!

I need some assistance today.  I have a custom application (IBM Resilient Integration) that I built out for my security response team and they would like to have a modification done to the checkboxes.  Yes, I have already approached them to use select boxes for the selections since it would be easier but they want the users to have to opportunity to select one or more checkbox while making a selection mandatory with an alert if nothing is selected.  

Below are the checkboxes that I'm using:

find_real_file.png

Any guidance or help is greatly appreciated!

Thanks,

Terry 

1 ACCEPTED SOLUTION

Yes, understood the problem.

The earlier code returns error when atleast one of them is false.

so instead of || use && and then it will fire only if all of those are unchecked.

View solution in original post

31 REPLIES 31

If its 1 checkbox field, why can't you make this field mandatory for user to select atleast one

g_form.setMandatory("your_field_name",true);

if there are different fields, then you can write a client script on submit and check like below

if(g_form.getValue("field1")=='' || g_form.getValue("field2")=='' || g_form.getValue("field3")=='' || g_form.getValue("field4")=='') {

g_form.addErrorMessage("please select atleast 1 value");

}

Mark the comment as a correct answer and also helpful once worked.

Asifnoor,

I just went to grab some lunch but I will try this solution once I get back to my desk.

Thanks,

Terry Carter

Asifnoor,

 

I tried your code above but I guess I'm missing something since I'm not that fluent in java scripting.

 

Getting the error messages below for line #3:

Expected an identifier and instead saw '||'.
3Expected an assignment or function call and instead saw an expression.
3Missing semicolon.
3Expected an assignment or function call and instead saw an expression.
3Missing semicolon.
3Expected an identifier and instead saw ')'.
3Expected an operator and instead saw '||'.
3Expected an assignment or function call and instead saw an expression.
3Missing semicolon.
3Expected an assignment or function call and instead saw an expression.
3Missing semicolon.
3Expected an identifier and instead saw ')'.
3Expected an assignment or function call and instead saw an expression.
3Missing semicolon.

find_real_file.png

Hi,

Try like below.

if(g_form.getValue("customer") == "" || g_form.getValue("non_customer") == "" || g_form.getValue("team_member") == "" || g_form.getValue("vendor") == "" || g_form.getValue("other") == "" ) {

g_form.addErrorMessage("Please select atleast 1 checkbox");

}

Mark the comment as a correct answer and also helpful once worked.

Okay I will try now. Let you know a response as soon as possible. Thanks, Terry