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

Concentating Text in a Text Field

Avatar

Level 2

Hi all,

I am creating a form where the user can make multiple selection via checkbox's, and I am trying to have the selections entered into 1 text field.

eg,

checkbox1 = apple

checkbox2 = orange

checkbox3 = pear

if checkbox 1 and 2 are selected I want the text field to read "apple, orange"

if all 3 are selected I want to see "apple, orange, pear" etc.

My form has over 60 checkbox's that could be selected.

Is there a simple way to do this?

Thanks in advance

Pete

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

I assume your checkboxes have a binding value of apple, orange, pear and if all your checkboxes are under the same subform, (such as 'Selection' in the code below) you could try this JavaScript code in the calculate event of the text box;

var checkboxes = Selection.resolveNodes('#field.[ui.oneOfChild.className == "checkButton"]');

var values = [];

for (var i = 0; i < checkboxes.length; i++) {

if (checkboxes.item(i).selectedIndex == 0) {

  values.push(checkboxes.item(i).rawValue);

}

}

values.join();

Here is a link to a working sample,

https://sites.google.com/site/livecycledesignercookbooks/home/Fruit.pdf?attredirects=0&d=1

The expression Selection.resolveNodes('#field.[ui.oneOfChild.className == "checkButton"]') returns all checkbox fields within the subform Selection and a checkbox with a selectedIndex equal to zero is selected., the rest of the code builds an array and returns a comma separated string of the checkbox that are selected.

Hope this helps

Bruce

View solution in original post

6 Replies

Avatar

Correct answer by
Level 10

Hi,

I assume your checkboxes have a binding value of apple, orange, pear and if all your checkboxes are under the same subform, (such as 'Selection' in the code below) you could try this JavaScript code in the calculate event of the text box;

var checkboxes = Selection.resolveNodes('#field.[ui.oneOfChild.className == "checkButton"]');

var values = [];

for (var i = 0; i < checkboxes.length; i++) {

if (checkboxes.item(i).selectedIndex == 0) {

  values.push(checkboxes.item(i).rawValue);

}

}

values.join();

Here is a link to a working sample,

https://sites.google.com/site/livecycledesignercookbooks/home/Fruit.pdf?attredirects=0&d=1

The expression Selection.resolveNodes('#field.[ui.oneOfChild.className == "checkButton"]') returns all checkbox fields within the subform Selection and a checkbox with a selectedIndex equal to zero is selected., the rest of the code builds an array and returns a comma separated string of the checkbox that are selected.

Hope this helps

Bruce

Avatar

Level 7

I tackled a similar thing to this. Mine is slightly different and puts each item on a separate line, but it should give you the general idea.

I have a Button, a TextField and three checkboxes and the code uses FormCalc

form1.pageDocumentSetup.btnConcatFruit::click - (FormCalc, client)

var lb = "\u000a" //linebreak character code. Use to create a line break between each item.

TextField1.rawValue = null; //clears the text field when the button is clicked

if(cbApple.rawValue == 1) then TextField1 = concat(TextField1, lb, "Apple") endif

if(cbOrange.rawValue == 1) then TextField1 = concat(TextField1, lb, "Orange") endif

if(cbPear.rawValue == 1) then TextField1 = concat(TextField1, lb, "Pear") endif

Avatar

Level 2

BR001,

Perfect,  that is exactly what I what. Thanks very much.

The only problem I have is that when I enter anything into the calculate field the application closes.  No idea why.  So I can see the code in your example  but I am unable to add it to my form.

Anyway thanks very much for the help.

Avatar

Level 10

Hi,

It can be tricky getting calculate events to work, maybe worth moving your code to a button click event and either show the result in an app.alert() or assign it to the field.

Happy to have a look at your form if you are able to share, just add a link to the form in this thread.

Regards

Bruce

Avatar

Level 2

Yes it is tricky, found out that if the code isn't perfect it closes the application.

So when I added your code, the subform names was wrong.

Then I made a change so there was a space after the comma (values.join(", ");), but didn't use quotation marks around it initially.

Eventually I got it correct and it works perfectly.

Thanks again

Pete