How to hide the values of subcategories
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2024 12:54 AM
Hello Everyone,
We have a field called 'category' on the incident form, and based on the selected category, the subcategory field values are displayed. We have options A, B, C, and D for the category field, and options 1, 2, 3, 4, and 5 for the subcategory field. However, we want to hide the subcategory option '4' when 'B' is selected in the category field. How can we achieve this?
Note: We only want to hide this option on the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2024 04:13 AM
Hi @SmithO ,
You can use onChange client script to dynamically modify the available options in the subcategory field based on the selected category.
Use the following script to hide subcategory option '4' when category 'B' is selected:
(function executeRule(current, previous) {
if (current.category == 'B') {
var subcategoryField = g_form.getControl('subcategory');
if (subcategoryField) {
var options = subcategoryField.options;
for (var i = 0; i < options.length; i++) {
if (options[i].value == '4') {
options[i].style.display = 'none';
}
}
}
} else {
var subcategoryField = g_form.getControl('subcategory');
if (subcategoryField) {
var options = subcategoryField.options;
for (var i = 0; i < options.length; i++) {
options[i].style.display = '';
}
}
}
})(current, previous);
If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.
Thanks,
Pooja Manchekar