Unable to set value of checkbox using Catalog Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2018 09:50 PM
Hi everyone
I am facing 2 issues
1. I am trying to set value of a checkbox using catalogclient script. But it is not working. I tried below options
g_form.setValue('x', true);
g_form.setValue('x', 'true');
g_form.setValue('x', 1);
g_form.setValue('x', '1');
2. I am setting checkbox to mandatory in a catalog ui policy. But that is also not working
Any ideas on this front will be welcome
Regards
Hetal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2018 10:08 PM
Hello Hetal,
1- g_form.setValue('x', true);
2- Using Catalog Client Script you can make as mandatory.
function onSubmit(){
//Set the mandatory checkbox variable names and total mandatory count here
var mandatoryVars = 'option1,option2,option3,option4';
var mandatoryCount = 2;
var passed = forceMandatoryCheckboxes(mandatoryVars, mandatoryCount);
if(!passed){
//Abort the submit
var message = 'You must select at least ' + mandatoryCount + ' options.';
g_form.addErrorMessage(message);
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.hasField(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-28-2018 10:16 PM
Hi Nayan
This solution is in case where i want to validate on submit
In my case i want to make the checkbox mandatory (it works fine when i set the checkbox variable as mandatory in the variable definition itself) using a catalog ui policy
Regards
Hetal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2018 10:23 PM
You need to check them in the onsubmit script
if (g_form.getValue('x')==false || g_form.getValue('x')=='')
{
g_form.showFieldMsg('x','Please check the box','error');
return false;
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2018 11:21 PM
I have written below simple code in onLoad script and it is working.
function onLoad() {
//Type appropriate comment here, and begin script below
g_form.setValue('checkme',true);
}
similarly I have made this checkbox mandatory using UI policy. This is working too.
See screenshots.
Hope this helps.
Hit Like / helpful/ Answered as applicable.
Thanks,
Jotiram