- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2024 09:31 PM
Hi All,
I want to allow user to select only 2 checkbox and other 2 should be readonly.How to achieve this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2024 02:24 AM - edited 02-18-2024 02:31 AM
Hi Sachin,
Try the below script, and make sure of below points:
1. If you are having 4 checkboxes, then you need to write 4 onChange client script one for each checkbox. But code in each script will remain the same. Only replace the backend name of checkbox with your's [That's only change needed in the script]. For me this scripts works as per your requirement. In my example I have 5 checkboxes where you can select only 2 checkboxes (any).
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var checkBoxes = ["checkbox1", "checkbox2","checkbox3","checkbox4","checkbox5"]; //Replace backend name of all checkboxes
var uncheckedBoxes = [];
var checkedBoxes = [];
checkBoxes.forEach(function(item){
if(g_form.getValue(item) == "false")
uncheckedBoxes.push(item);
else
checkedBoxes.push(item);
})
if(checkedBoxes.length == 2){
uncheckedBoxes.forEach(function(item){
g_form.setReadOnly(item,true);
});
}
else{
uncheckedBoxes.forEach(function(item){
g_form.setReadOnly(item,false);
});
}
}
Let me know if this works for you.
Please mark my response as Correct if it solves your problem and hit Helpful if this rings the bell.
Thanks,
Kamlesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2024 10:45 PM
onchange of which check box we should create, there 4 checkboxes corresponding to 4 variables. In that we would have to create 4 catalog client script for each varaibale
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2024 11:19 PM - edited 02-17-2024 11:23 PM
yes 4 client scripts for 4 varaibles, (i know its uffff). Or else go for Catalog UI policy. This will do the job with 1 Uipolicy
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2024 11:21 PM
No i didn't
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2024 11:25 PM
Why dont you do this on OnSubmit validation ? this will limit you to 1 script ! If more than 2 checkbox are selected you can unclear all varaibles and trow an error message.
or else the only option is UI policy...
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2024 11:27 PM
To achieve it through ui policy should i have to create 4 ui policy like below:
We have to create to 4 ui policies to acheive for all checboxes right?
1.A&B true then C&D false
2. B&C true then D& A false
3. C&D true then A&B false
4. D&A true then B&C false