- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-05-2021 08:16 AM
Hello,
I have a request to show choice options based off of a selection made. This needs to be an onChange client script. I have a category and subcategory field. Corresponding subcategories need to display for the selected category. Subcategory choices are currently set in the field.
My issue that I am facing is I can remove the choices, but they do not get readded back if a different category is selected. Also, if I use the addOption, I get a huge white space in my select box for the subcategory. Also, the clearOptions on the onChange only clears the options if an item is selected.
What is the best way to do this?
onChange Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var category = g_form.getValue('u_category');
g_form.clearOptions('u_subcategory');
if(category == 'accounting') {
g_form.removeOption('u_subcategory', 'strategy');
g_form.removeOption('u_subcategory', 'planning');
}
if(category == 'marketing') {
g_form.removeOption('u_subcategory', 'financial');
g_form.removeOption('u_subcategory', 'auditing');
g_form.removeOption('u_subcategory', 'quick_books');
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-05-2021 08:21 AM
Go check out Incident and see how they made it work. But essentially all you do is go to the dictionary for Subcategory and make it dependant on Category. Then pick a category, then jump to subcat right click and set up the choices. Then save and go back and pick the next choice. So what I am saying is this can be done with 0 coding.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-05-2021 08:19 AM
you need to add them back in
g_form.addOption(field,choice value, choice label, order)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-05-2021 08:21 AM
Go check out Incident and see how they made it work. But essentially all you do is go to the dictionary for Subcategory and make it dependant on Category. Then pick a category, then jump to subcat right click and set up the choices. Then save and go back and pick the next choice. So what I am saying is this can be done with 0 coding.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-05-2021 08:32 AM
I like this option much better. So I've selected the dependent and set subcategory to be dependent on category. When I go into the choice, how do I set the dependent value there?
Would I do "category.accounting" as the dependent value for all the choices using the accounting category? Also which field should I reference on the incident table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-05-2021 08:37 AM
This worked! Thanks