Adding Dynamic Child Objects to Widgets

Hello All,

I’ve been searching for a couple days on how this might be possible and I am starting to think that it is NOT.

In short: I want a number of text boxes to appear on a widget based on a number input field. I don’t know the number of text boxes that may be created as it could be very high (100’s).

Is there a way to add a child to a widget without having first made something to add to it? Can I create a “template” child widget component and have that be created over and over again with a new ID?

I will also need to be able to read the values of all these input fields after they have been created and I’m not clear on how I would do that.

Any help would be greatly appreciated.

Thank you

Yes you can. But you can only add entire widgets dynamically, not create widget components (the stuff in the list in the Designer view).

For example, if you want to dynamically add text boxes to a vertical box:

  1. Create a widget and put a Text Box in it. This will be the widget that you create dynamically later.
  2. In the widget that contains the Vertical Box, do Create Widget and pick the widget at Step 1.
  3. Get a reference to your Vertical Box and do Add Child.
  4. Connect the output from the Create Widget into the Add Child node.
  5. Add the output from the Create Widget node into an array so you can access it later.

You can do this with anything that can contain more than 1 child, like Horizontal/Vertical boxes, scroll boxes, etc.

3 Likes

I was working on something similar and based on your explanation here is what i have done in the screenshot. however, now when the children are added it isn’t adding all of them or adding the number i am expecting…

for instance when i want to add 4 boxes it just adds three… i think its not counting the zero index?

for anyone who is having problems with this as i am heres how to correctly create an array with a desired index size…

you need to use RESIZE node…

2016-10-05_17-57-50.png

this allows you to have an array valuable with a starting number of index items of 0
then you can resize it based on a value you determined elsewhere (in this case its a spin box for me)
then like in my case you can run a for each against that newly resized array

I would have put the Create Widget node inside of the For loop, not before. It’s weird to me that your setup works, because you’re referencing the same created widget instance multiple times and adding that same widget instance to your list multiple times.

I was under the impression you would need to create a new widget as many times as you want to add it, but it looks like the Add Child node either creates those instances itself, or I misunderstood the system.