if category is none hide the subcategory field using client script

aparna reddy1
Tera Contributor

hii all, 

please can anyone answer this question?

I have this question if category value is none hide the subcategory field using client script.

 

please help me out form this.

thanks in advance

3 REPLIES 3

Shruti
Mega Sage
Mega Sage

Hi,

Please try below onChange client script on Category field

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (newValue === '') {
        g_form.setDisplay('subcategory', false);
        g_form.clearValue('subcategory');
        return;
    }
    g_form.setDisplay('subcategory', true);

}

Filipe Cruz
Kilo Sage
Kilo Sage

Hi Aparna,

It might be worth to give a try to UI policies.

You can set a ui policy triggered when category is not empty, that will have an associated ui policy action to set the subcategory field visible (and possibly mandatory).

If you check the flag "reverse if false" it will hide automatically the subcategory field. I consider this easier to implement and to maintain compared with the client script.

Give it a try!! Hope it helps!

Hi Cruz

What to do if we don't  want sub category field to display if the selected category value has no dependent options in subcategory?