Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How can I make check boxes generate paragraphs of text

Contributor ,
Mar 06, 2017 Mar 06, 2017

Hi,

How can i make check boxes generate text?

I have 9 check boxes, each with their own individual Export Value. (The Export Value is a paragraph of text.)

I would like it so when people choose the check boxes they need, the result is shown in a text field, so I'm trying to write a custom calculation script.

My Checkboxes are called "Check Box 1" "Check Box 2" etc, and the results box is called "Strength results".

I can get it so I get all the text in one line, and the the word "Off" for each checkbox that isn't checked however I'm wanting:

Check Box 1 text (or which ever is selected)

Line break \n

Check Box 2 text (or which ever is selected)

Line break \n

Check Box 3 text (or which ever is selected)

Can you help?

Thanks

TOPICS
Acrobat SDK and JavaScript
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 06, 2017 Mar 06, 2017

Rename your checkboxes to "CheckBox.1", CheckBox.2" etc. then use the following code as your calculation in the field where you want the paragraphs to appear. "\n\n" will put an additional line break between the paragraphs.

var paras = [];

var fields = this.getField( "CheckBox" ).getArray();

// sort by name

fields.sort( function( a, b ) {

     var nameA = a.name.toUpperCase(); // ignore upper and lowercase

     var nameB = b.name.toUpperCase(); // ignore upper and lowercase

     if ( nameA < nameB ) {

 

...
Translate
Community Expert ,
Mar 06, 2017 Mar 06, 2017

Rename your checkboxes to "CheckBox.1", CheckBox.2" etc. then use the following code as your calculation in the field where you want the paragraphs to appear. "\n\n" will put an additional line break between the paragraphs.

var paras = [];

var fields = this.getField( "CheckBox" ).getArray();

// sort by name

fields.sort( function( a, b ) {

     var nameA = a.name.toUpperCase(); // ignore upper and lowercase

     var nameB = b.name.toUpperCase(); // ignore upper and lowercase

     if ( nameA < nameB ) {

          return -1;

     }

     if ( nameA > nameB ) {

          return 1;

     }

     // names must be equal

     return 0;

} );

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

     var field = fields[ i ];

     if ( field.isBoxChecked( 0 ) ) {

          paras.push( field.value )

     }

}

event.value = paras.join( "\n\n " )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 06, 2017 Mar 06, 2017

Amazing!! this is perfect.

Thank you so much Joel

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 07, 2017 Mar 07, 2017

Another question if anyone knows the answer (not as pressing as the other, hence not creating another thread).

We can set the Export Value of check box to be text easily within the properties menu, however, how can you insert a line break in a body of text in the export value? So you can export multiple paragraphs, as opposed to one...Any ideas?

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 07, 2017 Mar 07, 2017
LATEST

You can only do that using a script, but it's not recommended. If you really want to do it I would recommend replacing the line-breaks with some kind of place-holder character, like the pipe symbol ("|"), and then you'll just need to replace it back when applying the value to your multiline text field.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines