Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Dynamically Add to List Box (image included)

Avatar

Level 2

When I click the "Add Affiliation" button, I would like it to add the item number associated with that particular subform row added to the listbox below it. I calculate the item number from the index (the text field is called "txtCalcItemNumber").

Screenshot.png

This is what is in my click event for btnAddAffiliations:

Page1.Affiliations.Details.instanceManager.addInstance();

(i tried the code below to add items to listbox but doesn't work)

var values = xfa.resolveNode("Page1.Affiliations.Details[" + this.parent.index + "]").txtCalcItemNumber.rawValue;

ListBox1.addItem(values);

THANKS FOR YOUR HELP!!

1 Accepted Solution

Avatar

Correct answer by
Level 10
12 Replies

Avatar

Level 10

ListBox1.addItem(values, values);

the method addItem needs to param;

1st: Display Value

2nd: Bound Value

you can also set the bound value as an index

ListBox1.addItem(values, ListBox1.length);

Avatar

Level 2

Thank you for your reply

Just tried adding the bound value and code is still not working right

Avatar

Level 10

ok.. euhmm the other thing i can think of would be converting index into string

this.parent.index.toString()

Avatar

Level 2

Still nothing :/

Here is the form in case you would like to look at it

https://www.dropbox.com/s/kjzwkl4f99u1bi2/Testing.pdf

Avatar

Level 10

Yea i would, but the link ain't working

Avatar

Level 2

Try this link and see it if works. Be sure to click the blue download button

https://files.acrobat.com/preview/0a09eddd-6d7a-435c-8fa7-bb2dd3ef857a

Avatar

Correct answer by
Level 10

Try this out

Avatar

Level 2

Awesome! I tried it out and seems to work
One other thing (forgot to mention), is it possible to have the List Box have 1 as the initial number (since there is already 1 affiliation visible on the screen) and then when you click to add another affiliation, it places 2 in the List Box, etc.. Does this make sense?

Thank you for your help!

Avatar

Level 10

Yes, just add an itme in the listbox in the object palette, and then in the code,

when u add the item in ur listbox, add 1 to your value...

     or

Avatar

Level 2

Hi Robert,

I appreciate your help! I tried the following code and I seem to keep getting "1" added. I have attached my updated file to show you what I mean.

https://files.acrobat.com/a/preview/0a09eddd-6d7a-435c-8fa7-bb2dd3ef857a

Thanks again!

Avatar

Level 10

okay, cuz ur values are strings, we can't add 1 to it or else it will concatenate both value as strings

so you need to convert the string to int value like this

AffiliationListBox.addItem((parseInt(values) + 1).toString(), (parseInt(values) + 1).toString());

Avatar

Level 2

Thank you for all your helpful information!!