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

Acrobat Form Calculated Field Problems

Explorer ,
Jan 21, 2024 Jan 21, 2024

Copy link to clipboard

Copied

Happy New Year all.

 

I have created an Acrobat form that includes -
Text Fields: ContactName, ContactPhone, ContactEmail, AgeGrp, TeamName, MyInfo

Radio Button: HC

Drop-down Lists: DivisionH, DivisionC, TeamH, TeamC

 

Things to note:

  • HC is used to hide either the _C or _H drop-down fields as each is set with specific options on their list.
    • I may try to figure out how to dynamically control the options shown in the drop-downs rather than hiding/showing, but that is not my current issue.
  • Because of how the data from the form will be processed once received, I want to concatenate all the field values into a single field. Specifically MyInfo.

 

My issues:

  • I can get simple versions of this to work, but when I try to get the if/then required for choosing which of the drop-down list values to include in the concatenation everything breaks.
  • even when things are "working" in a simple version, the calculated value of MyInfo does not update when one of the contributing fields is changed.
  • There will be some blank fields. If I can leave them out of MyInfo that would be great.
  • Me. I'm the biggest issue here as my javascript is rusty.

 

Any help would be greatly appreciated and I'm happy to answer any questions. I have attached a copy of the form.

 

Rob

TOPICS
Create PDFs , How to , JavaScript , Modern Acrobat , PDF , PDF forms

Views

385

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 , Jan 22, 2024 Jan 22, 2024

Use division/Team in line with "AgeGroup".

str.push(this.getField("AgeGroup").valueAsString+" "+Division+" "+Team);

Then last line use like this:
event.value = str.join("%");

If you want to show each item in a new line, set the text field to multiline and replace "%" with "\n".

Votes

Translate

Translate
Community Expert ,
Jan 22, 2024 Jan 22, 2024

Copy link to clipboard

Copied

There is no "MyInfo" field in your file.

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
Explorer ,
Jan 22, 2024 Jan 22, 2024

Copy link to clipboard

Copied

Sorry. Wrong version of the form. I have updated the attachment.

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 ,
Jan 22, 2024 Jan 22, 2024

Copy link to clipboard

Copied

Please post the right file with your current code.

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
Explorer ,
Jan 22, 2024 Jan 22, 2024

Copy link to clipboard

Copied

My apologies. I used the wrong version of the form. The attachment has been updated.

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 ,
Jan 22, 2024 Jan 22, 2024

Copy link to clipboard

Copied

the calculated value of MyInfo does not update when one of the contributing fields is changed.

Place script in custom calculation script instead of 'On Blur' action.

In your script, you use "AgeGrp" for field name, but actual name is "AgeGroup".

Use this in "MyInfo" field as custom calculation script, see if that is close to what you want and you can work it from there:

var Division = "";
var Team = "";
var str = [];
if (getField("HC").value == "H") {
    // Include DivisionH and TeamH
    Division = getField("DivisionH").valueAsString;
    Team = getField("TeamH").valueAsString;
} else if (getField("HC").value == "C") {
    // Include DivisionC and TeamC
    Division = getField("DivisionC").valueAsString;
    Team = getField("TeamC").valueAsString;
}
if(this.getField("ContactName").valueAsString !== "")
str.push(this.getField("ContactName").valueAsString);
if(this.getField("ContactPhone").valueAsString !== "")
str.push(this.getField("ContactPhone").valueAsString);
if(this.getField("ContactEmail").valueAsString !== "")
str.push(this.getField("ContactEmail").valueAsString);
if(this.getField("AgeGroup").valueAsString !== "")
str.push(this.getField("AgeGroup").valueAsString);

event.value = str.join("%")+ Division + Team;

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
Explorer ,
Jan 22, 2024 Jan 22, 2024

Copy link to clipboard

Copied

Thank you so much. That is awesome. Can I bother you for one tweak? When I get the data from the form I use a find/replace to swap out the "%" for paragraph marks. The idea is to end up with info like attached. I can fill in the info for the rows, but I don't know how to get the "Division" and "Team" to be where I'd like them. 

 

I have attached the form with the updated script as well.

 

I've noticed that the form does not seem to be respectiong the required field status any more for some reason. Any ideas?

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 ,
Jan 22, 2024 Jan 22, 2024

Copy link to clipboard

Copied

Use division/Team in line with "AgeGroup".

str.push(this.getField("AgeGroup").valueAsString+" "+Division+" "+Team);

Then last line use like this:
event.value = str.join("%");

If you want to show each item in a new line, set the text field to multiline and replace "%" with "\n".

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
Explorer ,
Jan 22, 2024 Jan 22, 2024

Copy link to clipboard

Copied

LATEST

Perfect. Thank you again Nesa.

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