How to hide a mandatory field using catalog client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
You could achieve this with either a Catalog UI Policy or a Variable Set UI Policy. It likely depends on the use of the variable set. If it is only used in this catalog item or if you want this functionality to apply on all catalog items that use it then you should use a Variable Set UI Policy. If you want it to only apply on this catalog item and the variable set is used in other catalog items then create Catalog UI Policy.
I'm a bit curious about how you are setting the subcategories. If you aren't already you would probably be better off setting up the subcategory field using category as a dependent field. That would filter your subcategories natively without requiring any scripting.
Assuming this or that you can reference the subcategory the same way in your configuration, the key things to check when you create the UI Policy:
- It should Apply to the table the catalog item is associated with.
- Make sure onLoad, Global, and Reverse if False are checked (You may need to enable advanced view.)
- Condition will be "Subcategory" "Is One Of" "Selected Choices" (if this isn't available then you probably need to change to the dependent field configuration shown above.)
- You would then add a new UI Policy Action for the description field with Mandatory = "True", Visible = "True", and Read Only = "Leave Alone".
- Depending on your desired functionality, you may also need to create a separate rule to clear the value when the subcategory is not one of those that this policy applies to.
If the way you are populating the choices for SubCategory does not expose them to the UI Policy condition then you will need to use an onChange Script of the Subcategory variable that checks the selected value against an array containing the options you want description for and if it returns true then set description display and mandatory to true. The else would then set them to false and clear the value in description if desired.
