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

Script too long

Participant ,
Mar 03, 2023 Mar 03, 2023

Hello All,

Over the past few years you have all been very helpful and again im after some assistance/advice.

 

Is there anyway to  condense the attached script as when i try and add it to my selection properties in the custom calculation script it errors and says its too long

 

TOPICS
JavaScript , PDF forms
3.5K
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
1 ACCEPTED SOLUTION
Community Expert ,
Mar 03, 2023 Mar 03, 2023

There are a few different ways the script can be reduced, such as Bernd's suggestion. 

 

However, my prefered solution would be to make a design change to the form.  Right now the script is handling each field individually, which is inefficient for so many fields. It appears the fields are already divided into functional groups , so one solution is to use group naming. For example, "Group1.fieldname", where "Group1" is the group name. This type of naming allows all fields in the group to be accessed, and operated on, with a single line of code.

 

For example:  this.resetForm("Group1");  - Resets all fields in the group.    

 

Or: this.getField("Group1").display = display.hidden;  - hides all fields in the group

 

It's a lot of work to change the field names, but it will massively simplify handling the fields in a script. 

 

 

BTW:  the problem with the code being too long isn't a limitation in the form field script. It's a limitation of the script editor. Download NotePad++ and use it as the script editor, then there won't be a problem with the script length. 

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

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 03, 2023 Mar 03, 2023

E.g. you can split the script in several document level functions and use this functions.

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
Participant ,
Mar 06, 2023 Mar 06, 2023

Thank you Bernd.
This will work as an intrim fix until i can understand groups more

 

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 03, 2023 Mar 03, 2023

There are a few different ways the script can be reduced, such as Bernd's suggestion. 

 

However, my prefered solution would be to make a design change to the form.  Right now the script is handling each field individually, which is inefficient for so many fields. It appears the fields are already divided into functional groups , so one solution is to use group naming. For example, "Group1.fieldname", where "Group1" is the group name. This type of naming allows all fields in the group to be accessed, and operated on, with a single line of code.

 

For example:  this.resetForm("Group1");  - Resets all fields in the group.    

 

Or: this.getField("Group1").display = display.hidden;  - hides all fields in the group

 

It's a lot of work to change the field names, but it will massively simplify handling the fields in a script. 

 

 

BTW:  the problem with the code being too long isn't a limitation in the form field script. It's a limitation of the script editor. Download NotePad++ and use it as the script editor, then there won't be a problem with the script length. 

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Participant ,
Mar 06, 2023 Mar 06, 2023

Hi Thom,
How would i add the group designation to the code.
This solution would be extremly helpful in other areas of my form and hopefully speed up the form itself

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 06, 2023 Mar 06, 2023

You would need to rename the fields to start with the group name, followed by a period.

For example:

Group1.FirstName

Group1.LastName

Group1.DOB

Then you could show/hide all three fields using the code Thom provided.

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
Participant ,
Mar 06, 2023 Mar 06, 2023

Hello try67,

Sorry, I assume this then takes place in the Text Field Properties as below

px1.jpg

becomes

px2.jpg

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 06, 2023 Mar 06, 2023

Correct.

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
Participant ,
Mar 06, 2023 Mar 06, 2023
LATEST

Perfect,
Thank you very much for your help

 

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