How Do I Make Fields Required and Add Default Lines to an Object Group Based on a Control Value?

How Can We Help?

< Back

Answer

Background: If you want to make certain fields required or not based on the value of another control, you can use this snippet of code.

Make sure that the control (checkbox in this case) is set to “Auto Postback”. Place this code on the checkbox_OnRefresh.

Objective: If a checkbox is true, then display an object group and make the fields required.

ObjectGroup grp5 = activity.ObjectGroups.NamedItem("ObjectGroupName") ;
if (activity.GetControlValue("CheckBox") == "True")
{
grp5.Visible = true;
if (grp5.Lines <=0) //If there are zero lines in the object group....
grp5.AddLines(1); //Adding a default line
grp5["Field1"].Required = true;
grp5["Field2"].Required = true;
grp5["Field3"].Required = true;
}
else
{
grp5.Visible = false;
grp5["Field1"].Required = false;
grp5["Field2"].Required = false;
grp5["Field3"].Required = false;
}
Comments are closed.

This is the legacy version of the XMPro Documentation site. For the latest XMPro documentation, please visit documentation.xmpro.com

X