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

How can you add text to a results driven text box?

Contributor ,
Nov 10, 2017 Nov 10, 2017

Copy link to clipboard

Copied

Hi,

Is there anyway for a user to add text to a text box that has a custom script applied?

Joel_Geraci has given the following script which works perfectly, however I'm wondering if there's a way to do the same thing, only allow users to then add/change the text that's generated...any ideas?

Thanks

(My work around is simply put a separate text box at the side, but wondering if there's a script work around.)

var paras = [];

var fields = this.getField( “CB” ).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 " )

TOPICS
Acrobat SDK and JavaScript , Windows

Views

835

Translate

Translate

Report

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 ,
Nov 10, 2017 Nov 10, 2017

Copy link to clipboard

Copied

Swap the last line with the following.

event.target.defaultValue = paras.join( "\n\n " );

this.resetForm([event.target.name]);

This will set the assembled string as the default value then clear that field so that the default is present but editable.

Votes

Translate

Translate

Report

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 ,
Nov 10, 2017 Nov 10, 2017

Copy link to clipboard

Copied

Hi Joel,

Such a speedy reply! Thank you

... I can't get that to work unfortunately - it still removes the inputted text.

Here's part of the file I'm working on if it helps? WeTransfer

Thanks again

Votes

Translate

Translate

Report

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 ,
Nov 10, 2017 Nov 10, 2017

Copy link to clipboard

Copied

Do you mean you want the checkboxes to append to some existing text or do you want it to replace any existing text but still allow for editing after the replace?

Votes

Translate

Translate

Report

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 ,
Nov 10, 2017 Nov 10, 2017

Copy link to clipboard

Copied

Hi,

The latter...I'm not sure it's possible.

I'm wanting the user to choose the questions on page 1, that will then populate the text box on page 2. Then when the user goes to page 2, they might want to alter or drop notes on the questions, so it'd be good if it was editable.

If it's not doable (or not easy) don't worry, I think the work around of simply putting an additional text box to the side would do the trick just as well.

(In an ideal world what would happen is each question that's ticked would create a box on the next page with the question as the header, and then a text box underneath where they can add the text....but that, in my minute head, is faaaaar too tricky).

Votes

Translate

Translate

Report

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 ,
Nov 10, 2017 Nov 10, 2017

Copy link to clipboard

Copied

Ok then... go with this.

if (event.target.value == "") {

    event.target.defaultValue = paras.join( "\n\n " );

    this.resetForm([event.target.name]);

}

This will make the script update the field value only if it's empty.

Votes

Translate

Translate

Report

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 ,
Nov 10, 2017 Nov 10, 2017

Copy link to clipboard

Copied

LATEST

hmmmm...that doesn't seem to work either.

var paras = [];

var fields = this.getField( “CB” ).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 )

}

}

if (event.target.value == "") { 

event.target.defaultValue = paras.join( "\n\n " );  

this.resetForm([event.target.name]); 

Thanks so much for your help but don't worry - this feels like it's a pain so I don't want to use all your time. Thanks for trying though

Votes

Translate

Translate

Report

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