Mandatory CheckBox on Form

odinx16
Kilo Contributor

I need a Mandatory Checkbox as Acknowledgement on a form. The checkbox appears in certain conditions and has to be mandatory if it appears.
Currently I have the checkbox appearing correctly and when i have g_form.setDisplay('MyCheckbox',true), I also set:

g_form.setMandatory'MyCheckbox',true).

The asterisk appears next to the checkbox, but it is always grey. I can obtain the functionality I need with a Business Rule (before update), but my requirement is to actually make the asterisk red so that it is obvious.

Does anyone know a simple solution for this?

1 ACCEPTED SOLUTION

Rick Seiden
Mega Sage

I know this is an old post, so things have changed.  In London, at least, there is a "Selection required" checkbox on the variable form.  If you check that off, the user MUST check the checkbox.  No scripting required.

 

Rick Seiden

Linium

A Ness Digital Engineering Company

View solution in original post

10 REPLIES 10

brendanwilson84
Kilo Guru

You cannot make a true/false required. It defeats the purpose. If its required then its always gona be true , you need to check it to get rid of required stamp.



i suggest, having a yes/no choice field maybe?


Chuck Tomasi
Tera Patron

Hi Nicolae,



If you make any field mandatory, it simply says "Make sure someone puts a value here". Since a checkbox only contains a true or false value, it always contains SOME value, which makes mandatory kind of useless.



What you really want to validate is that someone checked the box, right?



You can do an onSubmit client script that does something like this:



var checked = g_form.getValue('MyCheckbox');



if (!checked) {


        g_form.addErrorMessage('You didn't check the checkbox!');


        return false;


}


How would you add a condition for additional checkboxes, and at the same time modify the error message to dynamically display to the user which checkboxes on the form they missed?


Same way, an onSubmit client script.



var list = [];


var checked1 = g_form.getValue('myCheckbox1');



if (!checked1) {


        list.push('My Checkbox 1');


}



// Repeat above bold lines for each checkbox...



if (list.length > 0) {


        g_form.addErrorMessage('You need to check the following checkboxes: ' + list.join(','));


        return false;


}