Concentating Text in a Text Field

Avatar

Avatar
Validate 1
Level 1
Missile64
Level 1

Likes

0 likes

Total Posts

14 posts

Correct reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
Missile64
Level 1

Likes

0 likes

Total Posts

14 posts

Correct reply

0 solutions
Top badges earned
Validate 1
View profile
Missile64
Level 1

01-09-2017

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile
_Bruce_Robertson
MVP

12-09-2017

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

Answers (5)

Answers (5)

Avatar

Avatar
Validate 1
Level 1
Missile64
Level 1

Likes

0 likes

Total Posts

14 posts

Correct reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
Missile64
Level 1

Likes

0 likes

Total Posts

14 posts

Correct reply

0 solutions
Top badges earned
Validate 1
View profile
Missile64
Level 1

14-09-2017

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

Avatar

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile
_Bruce_Robertson
MVP

14-09-2017

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

Avatar
Validate 1
Level 1
Missile64
Level 1

Likes

0 likes

Total Posts

14 posts

Correct reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
Missile64
Level 1

Likes

0 likes

Total Posts

14 posts

Correct reply

0 solutions
Top badges earned
Validate 1
View profile
Missile64
Level 1

13-09-2017

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

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
MinusZero
Level 4

13-09-2017

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

Avatar
Validate 1
Level 1
Missile64
Level 1

Likes

0 likes

Total Posts

14 posts

Correct reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
Missile64
Level 1

Likes

0 likes

Total Posts

14 posts

Correct reply

0 solutions
Top badges earned
Validate 1
View profile
Missile64
Level 1

07-09-2017

Any ideas?