Add widgets to a form at runtime

Add widgets to a form at runtime

Hi everyone,

I'm building an application where there is a form with a certain number of default fields/widgets (TextBoxes, ComboBoxes, Buttons, etc). In the application's administration area, an admin user has a feature where he can add adicional fields to that form.

My doubt is: how do I make those adicional fields/widgets appear in the form at runtime, since I cannot predict how many fields the admin user will add?

An example scenario is:
1. He accesses the form which has a certain number of fields.
2. He goes to the admin area and adds 2 new fields.
3. He goes back to the form and those 2 fields appear along with those which were already there.

How do I make those 2 new fields appear in the form?

Thanks in advance.

Best regards,
Ricardo Reis
Hi again,

Just one more detail: in the admin area, the admin user only enters data about the new fields (e.g.: label, data type, mandatory/not mandatory, etc.), and not the field/widget itself.

I really hope someone can help me, because this issue is driving me crazy for a long time now!

Thanks again.

Best regards,
Ricardo Reis
Ricardo -

There is a way to do this, but it isn't 100% smooth and easy.

Basically, you'll need to generate the widgets on-the-fly, based on the data the user entered. For example, you could run a query in Preparation to find out what widgets to make, then ForEach over them, building the table's HTML in a variable, and then using an Expression to put that HTML on the screen (use "Escape Content: False"). Alternatively you could make some JavaScript magic happen. Regardless, you'll need to do something on your own to get the HTML on the screen. Make sure that the names are predictable or saved in a screen variable.

When the user clicks the save button (or whatever triggers the "do something with these widgets!" logic), you will use one of the actions (it may be in the HTTPRequestHandler Extension) to access the form data directly, that's how you would read the data.

Let me know how this goes.

Best of luck!

Hi Justin,

First of all, thank you very much for your quick answer.

I really hoped there was some drag'n'drop-style solution for my question, you know.
But, anyway, I'll try to implement your suggestion that best fits my needs.

I'll let you know how it goes.

Ricardo Reis
Hi everyone,

As I promised, here is the solution I used to solve this problem.

The solution was to limit the amount of new fields the admin user can add to the form. With that, I was able to control wich fields appear in the form, and which do not, every time that user adds a new field.
I do this by putting on the form, at build time, all the fields the user, at the most, can add at runtime. To decide whether a field appears, I enclose it in an "If", with the condition being set to True, or False, in Preparation, according to certain factors.

Thanks, Justin, for your assistance.

Best regards,
Ricardo Reis