Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Creating Dynamic Lists

Avatar

Level 2

Hello All,

Does anybody know of a script that will allow me to add new Textfield instances that are populated with Data from another Textfield that can also be removed?  I've been racking by brains trying to figure out how to do this but whatever instance I create that contains data in it is automatically overwritten with any new instances with data that I create.

Thanks for any help!

4 Replies

Avatar

Level 10

Check the data binding for the Textfields..

     If you set it to Global, then all the fields with the same name will display the same value. That means if you add fields at runtime, they all carry the same name and so they alldisplay the same value.

But if you do not want to display the same value for the TextField on form and for the newly added TextFields, then you have to set it to either Normal/ None.

In your case, you probably have Global. Change it to Normal/ None.

Thanks

Srini

Avatar

Level 2

Thanks for your reply Srini.  After searching these boards, however, I discovered that you cannot simultaneously add an instance and populated it at the same time, unless, as you point out, the binding is set to global.

Thanks anyway.

Avatar

Level 10

Your assumption might not be coreect.

You can add an instance and still display value in the newly added field at the same time.

For example

     If you have a subform "Subform1" and inside the subform you have "TextField1". You want to populate the value of the TextField1 from TextField2.

     For Subform1, you set the "Repeat Subform for Each Data Item".

     Now you are adding new instance of Subform1 and want to display TextField1 with TextField2 data.

     The below code you can place in the click event of button while adding the new Instance.

     Subform1.instanceManager.addInstance(1);

     var intIndex = Subform1.instanceManager.count-1;

     //Resolve the Subform1 to the recently added instance and display the value.

     xfa.resolveNode("Subform1[" + intIndex + "]").TextField1.rawValue = TextField2.rawValue;

     The key here is to resolve the node to the recently added instance.

Hope this gives an idea.

Thanks

Srini

Note: TextField1 and TextField2 both are set to Normal/ None binding in the above example.

Avatar

Level 2

Thanks, again, Srini!

You've helped me with half of my problem.  I wish to create a "dynamic" list which will allow me to add an instance and populate it at the same time.  You've helped me tremendously with this.  Now, I wish to find a way to also remove an instance that was added, but not necessarily in the order that it was added. 

For example, when adding instances by clicking a button (outside the repeating subform), I create three instances with the following text fields in the order as follows:

aaaaaa

bbbbbb

cccccc

Now, I wish to click a button (again, outside the repeating subform) that will allow me to remove instances in the following order:

bbbbbb

cccccc

aaaaaa

Unfortunately, everything I've tried until now has only removed the first instance (aaaaaa) or the last instance (cccccc) and usually not in the order I wish them to be removed. 

Is there some way to remove specific instances based on the value of the text within the instance rather than on an index value?  I think this may be the way to go.

Again, thanks for any help out there.  This forum is simply fantastic!