How to Add Polymorph Field to a Screen Section

How to Add Polymorph Field to a Screen Section

This how-to will guide you through the process of adding a polymorph field to a screen section. The polymorph field is a special type of the input control, that changes its type (Textbox, ComboBox, CheckBox, etc.) according to the data.

1 - Create Fields in Underlying Entity

Polymorph field is represented in entity by a virtual field. Set its DataType property as Object. This will make sure, that when the column is dragged to a screen in the Screen Section Editor, MultiColumnAdapterFieldWrapper widget will be used.

Polymorph field behaviour is controlled by the content of another field. Such field has to be defined in the entity as well. There should be also some data fields, where the values will be stored in, but they are not necessary to make polymorph column runnable.

For the sake of the tutorial, let’s define a virtual field Polymorph, control field will be Lookup Field DataType (creation of Lookup Field is not part of this tutorial) and content columns BooleanContentField, FloatContentField, GuidContentField and TextContentField. Data types of the content columns are discernible from their respective names.

2 - Add MultiColumnAdapterFieldWrapper to a Screen Section

In Screen Section Editor, simply drag previously defined virtual field to the section area. MultiColumnAdapterFieldWrapper will be added. Set name of control field in ControlMember property. In case of tutorial ControlMember property value is DataType. DataType is control field, which we have defined in previous step.

3 - Set up Control Constants

The behaviour of MultiColumnAdapterFieldWrapper is controlled by values in ControlMember. We need to set up these values as constants, that will be referenced in by wrapped input controls. In our case these constants mirror the possible values of DataType field. For our example we have defined constants UseBooleanField, UseFloatField, UseGuidField and UseTextField.

3 - Add Input Controls to the MultiColumnAdapterFieldWrapper

Drag data fields you intend to use to the MultiColumnAdapterField Wrapper. For each input control select constant and set it in MappingCondition property. If control field has such value, this field and input control will be used, otherwise it won’t be visible. As shown in illustration, we have assigned UseTextField constant as MappingCondition for TextContentField input control.

You can drag multiple input controls to the wrapper. Since at maximum only one input control is supposed to be visible, you can arrange them in a column and wrapper itself will always set their Y property to the top. X property is taken from the input control unchanged.