- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2019 02:52 AM
Hello,
I have 10 checkbox variables created we want users to select at least 1 checkbox otherwise it should throw an error.
How to acheive this
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2019 04:33 AM
I've used the below script in an onSubmit Client Script
function onSubmit(){
//Set the mandatory checkbox variable names and total mandatory count here
var mandatoryVars = '<checkbox values here seperated by a ,>';
var mandatoryCount = 1;
var passed = forceMandatoryCheckboxes(mandatoryVars, mandatoryCount);
if(!passed){
//Abort the submit
alert('You must select at least ' + mandatoryCount + ' options.');
return false;
}
}
function forceMandatoryCheckboxes(mandatory, count){
//Split the mandatory variable names into an array
mandatory = mandatory.split(',');
var answer = false;
var varFound = false;
var numTrue = 0;
//Check each variable in the array
for(x=0;x<mandatory.length;x++){
//Check to see if variable exists
if(g_form.getControl(mandatory[x])){
varFound = true;
//Check to see if variable is set to 'true'
if(g_form.getValue(mandatory[x]) == 'true'){
numTrue ++;
//Exit the loop if we have reached required number of 'true'
if(numTrue >= count){
answer = true;
break;
}
}
}
}
//If we didn't find any of the variables allow the submit
if(varFound == false){
answer = true;
}
//Return true or false
return answer;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2019 03:03 AM
Hi,
If you have checkbox variable as true/false ,then you can not make mandatory. Since a checkbox only contains a true or false value, it always contains SOME value, which makes mandatory kind of useless.
If you have other options in checkbox then,you can make checkbox mandatory based on condition.
By using onChange, onSubmit and onLoad client script.
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;
}
Mark correct/helpful if it helps for you.
Regards,
Pooja
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2019 03:16 AM
This can be done for a single checkbox but i have 10 checkbix in which atleast if 1 checkbox is checked then it should pass only if the all the 10 checkbox are not filled it should fail.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2019 03:15 AM
Perhaps use a scripted Catalogue UI Policy?
If x & y & z variables are all false, make x & y & z variables mandatory. When one of the variables becomes True, they are no longer mandatory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2019 03:17 AM
You can write the onSubmit Client script and code will be like
if(checkbox1 != "true" && checkbox2 != "true" && checkbox2 != "true")//add the all checkboxes name including &&
{
alert("Select the checkbox");
return false;
}