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.

How to auto populate text field from number of checkboxes?

Avatar

Level 2

Hello there,

I am a newbie in Livecycle, and I need to populate a text field from checkboxes. There are many checkboxes in my form and depending on which checkbox do I check, the caption of the checkbox should be copied to another text field.

I could populate one checkbox in one text field, but when more than one checkboxes are checked, their caption should be added to the text field and when I uncheck it should be removed from the text field as well, how can I do that??

For example

CB1: Product List

CB2: Test Cert

CB3: QA Cert etc.

If I check CB1 and CB3 they should auto populate in one text field like "Product List, QA Cert"

Would appreciate any help on this.

Thank you

-Nisarg

5 Replies

Avatar

Level 10

Hi Nisarg,

If all you checkboxes are under a subform called 'Checkboxes', then you could use some JavaScript like the following in the calculate event of the text field.

var result = [];

// select all checkboxes that are children of the subform called 'Checkboxes' you will probably need to change this bit

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

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

  var checkbox = checkboxes.item(i);

  // if the checkbox is selected store in result array

  if (checkbox.rawValue == checkbox.items.nodes.item(0).value) {

  result.push(checkbox.caption.value.text.value)

  }

}

result.join(", ");

Here's a sample I used to check the syntax, https://sites.google.com/site/livecycledesignercookbooks/home/shahnisarg28.pdf?attredirects=0&d=1

Regards

Bruce

Avatar

Level 2

Hello Bruce,

Thank you very much for your quick reply. I found that this is working fine with the checkboxes floating in the page. I have a table and those checkboxes after editing the script are not responding. Can you please see what can be done on that?? Or any idea. Here is the edited file which you sent. The table is in a flowed subform and the text field is in another subform which is flowed too.

https://drive.google.com/file/d/0B1P_x_8vwoUFaWg1bUlWUVZYQjQ/view?usp=sharing

Really appreciate your help, thank you.

-Nisarg

Avatar

Level 10

Hi,

That layout makes things a bit harder, but try this code

var result = [];

var checkboxes = [];

function findCheckboxes(vContainer)

{

    if (vContainer.className == "field")

    {

        if (vContainer.ui.oneOfChild.className == "checkButton")

        {

            checkboxes.push(vContainer)

        }

    }

    else

    {

        var vChildren = vContainer.nodes;

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

        {

            var vChild = vChildren.item(i);

            if (vChild.isContainer)

            {

                findCheckboxes(vChild)

            }

        }

    }

}

findCheckboxes(Table14);

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

  var checkbox = checkboxes[i];

  if (checkbox.rawValue == checkbox.items.nodes.item(0).value) {

  result.push(checkbox.caption.value.text.value)

  }

}

result.join(", ");

I've updated my sample, https://sites.google.com/site/livecycledesignercookbooks/home/shahnisarg28%20(3).pdf?attredirects=0&...

This sample also shows an alternative to the table, and uses the original (and simpler) script.  Just in case you didn't have other reasons for using a table.

Also I haven't done anything special with the "other" option, should this be added to the text field as well?

Regards

Bruce

Avatar

Level 2

Hello Bruce,

Thank you very much, with slight modifications in my form, this script is working like a champ. And yes, you got me, whatever is entered in textbox beside "Others" should be included in the text field. I am trying to do that, but would really appreciate your help in doing this. I have to use a table here, as there are few other layouts also tied with these checkboxes in the form and also they are repeated as per the instructions by user.

Not being from the IT related field, its difficult to code this kind of actions, but by the help of friends like you, I am learning a lot.

The help you have offered is very appreciable. Could you please let me know how to code the text field of "Others"?

Thanking you,

Nisarg

Avatar

Level 10

Hi Nisarg,

Have a look at this sample  https://sites.google.com/site/livecycledesignercookbooks/home/shahnisarg28%20(4).pdf?attredirects=0&...

If has the following code added to it.

 

        var checkboxCaption = checkbox.caption.value.text.value;

         if (checkboxCaption == Table14.Row6.Table15.Row1.Others.caption.value.text.value &&

             !Table14.Row6.Table15.Row1.OthersTxt.isNull) {

             result.push(checkboxCaption + " " + Table14.Row6.Table15.Row1.OthersTxt.rawValue);

         }

         else {

             result.push(checkboxCaption);

         }

 

Glad I could help.

Bruce