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

Combining text fields into one to create a description

Participant ,
Jul 25, 2019 Jul 25, 2019

Copy link to clipboard

Copied

Hello everyone, I'm trying to create a group of fields that would have pre-populated text in the export value. Then combine those fields into one, which would make a complete sentence (or paragraph) of those field values. For example, Field1 would have "We propose to install". Then in Field2 would have the (total footage) "of 8' high CLF". In Field3 would have the total footage then "8' high WIF". In Field3 would have pretty much the same but this would be "of 8' high Wood Fence". Giving me the choice to show/hide the particular fields.

Is this something that can be done using javascript? I don't know enough but I'd like to learn. Or, does anyone know of a way to accomplish something like this in a PDF. I'd like to create a short cut to be able to put the combinations into a job description. If you can show me how to create the first one, then I can do the rest. Thank you all so much.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

908

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

correct answers 1 Correct answer

Community Expert , Jul 26, 2019 Jul 26, 2019

Sure. In the code, change all instances of "valueAsString" to "defaultValue".

Votes

Translate

Translate
Community Expert ,
Jul 26, 2019 Jul 26, 2019

Copy link to clipboard

Copied

Yes, this is easily done. You can use something like this as the custom calculation script of the final field:

event.value = this.getField("Field1").valueAsString + this.getField("Field2").valueAsString + this.getField("Field3").valueAsString;

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
Participant ,
Jul 26, 2019 Jul 26, 2019

Copy link to clipboard

Copied

Heya Gilad, thanks for the quick response. The script works, but only when I type some text into the field. What I would like to do is not have to type and have the text filled in the default value of each text field and have that text fill into the end text field. I'll probably hide the fields and only show them when needed. Can that be done?

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 ,
Jul 26, 2019 Jul 26, 2019

Copy link to clipboard

Copied

I don't understand what you mean... You want to combine the default values, not the actual values?

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
Participant ,
Jul 26, 2019 Jul 26, 2019

Copy link to clipboard

Copied

Yes. Is that possible? The Text Field Properties window. Options > Default Value. I have just typed in some text there and it doesn't change.

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 ,
Jul 26, 2019 Jul 26, 2019

Copy link to clipboard

Copied

Sure. In the code, change all instances of "valueAsString" to "defaultValue".

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
Participant ,
Jul 26, 2019 Jul 26, 2019

Copy link to clipboard

Copied

Right on the money. Thanks, Gilad. That was perfect. Now for part 2. I would like the default values to populate into the destination text field only if one or all 3 text fields are visible.

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 ,
Jul 27, 2019 Jul 27, 2019

Copy link to clipboard

Copied

You can use something like this, then:

var f1 = this.getField("Field1");

var f2 = this.getField("Field2");

var f3 = this.getField("Field3");

if (f1.display==display.visible || f2.display==display.visible || f3.display==display.visible)

    event.value = f1.defaultValue + f2.defaultValue + f3.defaultValue;

else event.value = "";

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
Participant ,
Jul 27, 2019 Jul 27, 2019

Copy link to clipboard

Copied

LATEST

Interesting. I'll have to play around with it later. You definitely know your stuff. Thanks for all your time.

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