How to hide a mandatory field using catalog client script?

The Matrix
Tera Contributor

Hi All,

I've written a onChange catalog client script on Subcategory field. whenever a specific subcategory is selected then the description field should be visible and should become mandatory. After Subcategory value changes back to --None-- the description field should be hidden (vice versa). I have written below script. It is not working. 

And we are adding category and subcategory choices via catalog client script. As these variables are from Variable set. How can I achieve this same functionality via catalog UI Policy. 

if (newValue == 'create_a_new_local_gcajob/sub_family') {
        g_form.setDisplay('description', true);
        g_form.setMandatory('description', true);
}
else 
{
        g_form.setMandatory('description', true); 
        g_form.setDisplay('description', true); 
}
        

 

10 REPLIES 10

Sarthak Kashyap
Mega Sage

Hi @The Matrix ,

I tried your problem in my PDI and it is working fine for me

Can you please try with UI Policy, 

 

SarthakKashyap_0-1761891086125.png

Create UI Policy Action 

SarthakKashyap_1-1761891114904.png

 

Result

When Option one is selected description is mandatory

SarthakKashyap_2-1761891152424.png

When Option two is selected description is not visible

SarthakKashyap_3-1761891177144.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak

 

 

 

 

Ankur Bawiskar
Tera Patron

@The Matrix 

try this once -> do clear the description when you are hiding it

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading)
        return;

    if (newValue == 'create_a_new_local_gcajob/sub_family') { // use correct value to compare
        g_form.setDisplay('description', true);
        g_form.setMandatory('description', true);
    } else {
        g_form.setMandatory('description', false);
		g_form.clearValue('description');
        g_form.setDisplay('description', false);
    }

}

💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏

@The Matrix 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏

Ravi Gaurav
Giga Sage

Hi @The Matrix 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) return;

// Target variable name: 'description'
if (newValue == 'create_a_new_local_gcajob/sub_family') {
g_form.setDisplay('description', true);
g_form.setMandatory('description', true);
} else {
g_form.setMandatory('description', false);
g_form.setDisplay('description', false);
g_form.clearValue('description');
}
}

Ravi Gaurav
Giga Sage

@The Matrix  if you feel like I am able to solve the problem .. Please accept the solution on the same !!