I have a requirement to set visible and set required field on chosing one option. I am able to set visible but not able to setRequiredLevel in client API.
if(selectedItemCurrent != null && selectedItemCurrent.includes(8))
{
formContext.getControl("comments").setVisible(true);
formContext.getControl("comments").setRequiredLevel("required");
} else
{
formContext.getControl("comments").setVisible(false);
formContext.getControl("comments").setRequiredLevel("none");
}
}
Or
formContext.getControl("comments").setVisible(selectedItemCurrent?.includes(8)&&setRequiredLevel("required"));
Both are throwing exception. Can someone help me in this?
You mentioned you can get the visible to work, so I assume the column name is correct. Please try using the getAttribute function instead of getControl when setting the requiredLevel
You can also do something like this:
let isVisible = (selectedItemCurrent != null && selectedItemCurrent.includes(8));
formContext.getControl("comments").setVisible(isVisible);
formContext.getAttribute("comments").setRequiredLevel(isVisible ? "required" : "none");
I am copying the documentation links for both methods.
Best regards