I've been tasked with creating a custom label control for Sitecore Forms. I've built the control, and it is working fine. One of the requirements is to allow content editors to associate the custom control with another existing input control on the form. The html contains a "for" property that I can use to associate the label with an input control on the form. My question is, how can I create a dropdown list property that contains a list of input controls for the content editor to choose from?
In the core database, there's a template for creating a property as a dropdown list called FormDropList Parameters. That template has a 'DynamicData' property, so I'm guessing this is where I would start, but I dont know where to go from there.
Since I couldn't figure out how to get a list of the existing controls on the form page, instead I came up with a workaround. I created a 'For' property as a textbox on the label control. A content editor could select the name of the input control to associate the label with and paste it in the 'For' property of the label. In the example below,
totalAmount
is the field name property of a number input control.Once the
totalAmount
input box gets rendered on the page, it looks similar to this. Notice thedata-sc-field-name="totalAmount"
property. This tells us what the field name property is of this input control in the form designer:Once we have the name given in the form designer, and the id/name properties that get rendered by Sitecore (based on the guid of the form and guid of the control), I could write a mapping function in jquery that gets executed when the document is ready. Here is the code for that function: