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

Why is it that when I click Acrobat's Clear Form option is clears all the fields populated by a document level JavaScript, and if I save the form the start up document level JavaScript no longer functions?

Community Beginner ,
Apr 29, 2016 Apr 29, 2016

Why is it that when I click Acrobat's Clear Form option is clears all the fields populated by a document level JavaScript, and if I save the form the start up document level JavaScript no longer functions?

TOPICS
Acrobat SDK and JavaScript , Windows
1.1K
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

LEGEND , Apr 29, 2016 Apr 29, 2016

Or a link to the form or a sample form with the same problem.

You have only defined the function to be executed but not executed it.

You need to add a line like:

AtStartup();

to your script.

As noted if you were set the "defaultValue" for the fields then clearing the fields would remove any entry present and restore the default values.

Or you could write a custom JavaScript to clear the fields and then execute your startup script.

Translate
LEGEND ,
Apr 29, 2016 Apr 29, 2016

Can you post the script you're using?

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 ,
Apr 29, 2016 Apr 29, 2016

The "reset a form" action that you can use as e.g. a button click handler will reset all fields to their default values. You can set the default value as part of the field properties. Resetting a form should not have any effect on document level functions. Are you getting any error message in the JavaScript console? What exactly is your document level script doing that is no longer working?

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 Beginner ,
Apr 29, 2016 Apr 29, 2016

Not getting any errors in the JavaScript console. When I open the form the document level function runs ok. If I use Acrobat's built in Clear Form option it clears the document level function population of various fields on opening the form. If I then save the form the document level function no longer populates these fields. If I place the contents of document level function in a custom calculation script it runs ok and populates all the fields. 

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 ,
Apr 29, 2016 Apr 29, 2016

Once again, what exactly does your document level script do? Please post the whole script.

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 Beginner ,
Apr 29, 2016 Apr 29, 2016

The function is named AStartUP

function AStartup()

{

this.getField("txtRowNo.0").value = "01" ;

this.getField("txtRowNo.1").value = "02" ;

this.getField("txtRowNo.2").value = "03" ;

this.getField("txtRowNo.3").value = "04" ;

this.getField("txtRowNo.4").value = "05" ;

this.getField("txtRowNo.5").value = "06" ;

this.getField("txtRowNo.6").value = "07" ;

this.getField("txtRowNo.7").value = "08" ;

this.getField("txtRowNo.8").value = "09" ;

this.getField("txtRowNo.9").value = "10" ;

this.getField("txtRowNo.10").value = "11" ;

this.getField("txtRowNo.11").value = "12" ;

this.getField("txtRowNo.12").value = "13" ;

this.getField("txtRowNo.13").value = "14" ;

this.getField("txtRowNo.14").value = "15" ;

this.getField("txtRowNo.15").value = "16" ;

this.getField("txtRowNo.16").value = "17" ;

this.getField("txtRowNo.17").value = "18" ;

this.getField("txtRowNo.18").value = "19" ;

this.getField("txtRowNo.19").value = "20" ;

)

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 ,
Apr 29, 2016 Apr 29, 2016

In addition to the need to actually call the file, there is also a syntax error in your script: A function definition is wrapped in { and } - you start with a {, but end with a ) on the last line. Change the last line to } (and call your function), and you should be all set. To call the function, just add the call to your function as the last line of your document level script.

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
LEGEND ,
Apr 29, 2016 Apr 29, 2016

Or a link to the form or a sample form with the same problem.

You have only defined the function to be executed but not executed it.

You need to add a line like:

AtStartup();

to your script.

As noted if you were set the "defaultValue" for the fields then clearing the fields would remove any entry present and restore the default values.

Or you could write a custom JavaScript to clear the fields and then execute your startup script.

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 Beginner ,
Apr 29, 2016 Apr 29, 2016

Testing the form I notice if the fields that the document level populates are blank when saved, the form takes some time to open. But if the form is saved with the fields populated the time to open is noticeably quicker. Is there a better method for populating text fields with values?

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
LEGEND ,
Apr 29, 2016 Apr 29, 2016

That can happen if Acrobat isn't opened, or if it is, if the JavaScript engine hasn't been started. So the delay is the JavaScript engine starting up. If you close the form and leave Acrobat running, if you reload the form you probably won't see a delay.

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
LEGEND ,
Apr 30, 2016 Apr 30, 2016
LATEST

I would expect there is a lot more going on than just this one script that is slowing down the form's opening. I would consolidate as many of the scripts as possible and possibly changing where some of the scripts run. Not all fields need to updated the calculation script. For example check boxes and radio button could update other field by use of the mouse up action in some instances.

For the default value of the form fields in question I would have use the field's' properties to set the Default Value on the Options tab.

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