Expand my Community achievements bar.

SOLVED

Popolate scripts

Avatar

Level 2

Is there a way to populate script events? I have a lot of text fields using the same script events. And I got trouble running the PDF file, it can't be open. I guess the scripts are so heavy to run. Any idea would help

Edigo

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

If you have a look at the Prerequisites field in the docReady; enter; exit; prePrint; and postPrint events. You will see how I am calling the functions. There are two functions in the myScriptObject. 

Hope that helps,

Niall

View solution in original post

14 Replies

Avatar

Level 10

Hi,

I don't think this is your problem. The form should open in Acrobat.

One way would be to take the script and put it into a function. Then each textfield would call the function. One advantage is that the script is in one location which makes it easier to maintain.

First right-click on "form1" node and select "insert script object". It will appear unnamed in the hierarchy under Variables. Give it a unique name:

script object 1.png

Click the script object and paste your script into it (script editor). Note that you can only use JavaScript in a script object.

Now at the start of the script define the function by giving it a unique name (different from the name of the script object); stating the variables from the form that will be used in the function and start the function with a curly bracket. Then go down to the end of your script and close the function with a curly bracket.

myFunction(str)

{

     ...

     your script

     ...

} // close function

Then in the textfields you can call the function like this:

myScriptObject.myFunction(this.rawValue); 

You would put this in the same event that the script was originally in. You would pass the same values to the function that was used originally in your script. Note that when you call the object you give the full SOM of the objects you are referencing (eg this.rawValue) but in the script object this is then referenced by "str", so you would use "str" throughout your function.

There are lots of examples of functions on the forum and on the Adobe website.

Hope that helps,

Niall

Avatar

Level 2

Hi Niall,

Thank you for your answer. But I lost while trying to figure out how to do it. Could you please help do it?

I'd like to add the following scripts to text fileds to Course details, Contacts hours and Instructor Details as how example file works. Thanks a million

form1.#subform[0].#subform[1].TextField1::enter - (JavaScript, client)


this.fontColor = "0,0,0";

this.font.posture = "normal";


form1.#subform[0].#subform[1].TextField1::exit - (JavaScript, client)


if (this.isNull)

{

this.fontColor = "153,153,153"; // a gray colour

this.font.posture = "italic";


form1.#subform[0].#subform[1].TextField1::postPrint - (FormCalc, client)


this.format.picture.value = "null{'" + this.assist.toolTip.value + "'}";


form1.#subform[0].#subform[1].TextField1::prePrint - (FormCalc, client)


this.format.picture.value = "";


form1.#subform[0].#subform[1].TextField1::initialize - (JavaScript, client)


this.execEvent("exit");

this.format.picture.value = "null{'" + this.assist.toolTip.value + "'}";

Avatar

Correct answer by
Level 10

Hi,

If you have a look at the Prerequisites field in the docReady; enter; exit; prePrint; and postPrint events. You will see how I am calling the functions. There are two functions in the myScriptObject. 

Hope that helps,

Niall

Avatar

Level 2

It's awesome. But still not clear to me. I guess I don't have background in using scripts. If I really want to learn it, where can I start?

Avatar

Level 10

Hi,

There is a lot of information on the Adobe website and in the forums.

There are free guides on the Adobe web site which cover Acrobat and LC:

http://www.adobe.com/go/learn_lc_scriptingBasics

http://www.adobe.com/go/learn_lc_scriptingReference

http://www.adobe.com/go/learn_lc_formCalc

http://www.adobe.com/devnet/livecycle/articles/Adobe_XML_Form_Object_Model_Refer ence.pdf

http://www.adobe.com/devnet/acrobat/pdfs/lc_migrating_acrobat_xmlform.pdf

And a very handy resource (and while it is for version 6 it is still very good because of the way it is laid out): http://partners.adobe.com/public/developer/en/tips/CalcScripts.pdf

JP Terry's book on LC Forms is very good and we use www.pdfscripting.com (which is a subscription service).

The help file also helps with syntax and LC Designer comes with templates/examples.

Lastly, check out the Developer's Network on http://www.adobe.com/devnet/livecycle/

Good luck,

Niall

Avatar

Level 2

The form I made is run properly in Adobe Reader/ Acrobat version 9 but not version 8 or below, even I saved the form as "version 8.0 /7.0.5 or later"


I got problem with some fields such as Contact hours, and other text fields below that I cannot type anything if I open the form with version 8.

Since many users still use old versions, it really freaks me out. Any ideas how to fix that?

Thanks in advance,

Edigo

Avatar

Level 10

Hi Edigo,

If you look in the warnings tab and log you will see that one thing it doesn't like is the hyphens:

LittleSnapper1.png

If you select an object and look in the Paragraph tab you will see that you have selected hyphenate. I can't deselect this for some reason:

Parallels Desktop1.png

So if you keep the object selected and go into the XML Source tab you will see the start of the object in the xml and further down you will see the paragraph/hyphenate setting:

Parallels Desktop2.png

Now if you selected the hyphenate line:

Parallels Desktop3.png

and delete it:

Parallels Desktop4.png

Go back to the Design view (clicking Yes to save the changes) and the tick will be gone from the hyphenate checkbox.

I have done the four textfields under Contact Hours. Can you test this in v7 and see if that works.

If it does then you would need to follow the same process of removing all occurrences of default__hyphenate from the XML Source.

Let me know how you get on.

Niall

Avatar

Level 2

Hi Niall,

I deleted all the hyphenations and tested with Adobe Reader 8/ 9, Acrobat Professional 8.0/ 9. It works fine

But the problem still occurs in some other version such as Acrobat Professional 8.1/ 8.2 (as far as I know, from some people who got in trouble). Those are upgrades of version 8, it is supposed to run, but not. I just don't understand

Edigo

Avatar

Level 10

Hi Edigo,

Sorry about the delay - just one of those days!!

I have had a look at the form and all appears to be OK. The hyphenation is clear and there are no errors. I would have expected the form to work now.

Like you, when it worked for v8, I would have expected it to continue to work for all versions up to v9.3.1. Sorry I can't explain why it is not working for v8.1 and v8.2.

I have Reader v8.1.3 and I have tested the form. Even though the access to the fields is open, the user cannot click into them. Also the text that is normally hidden until the user clicks into the field, are visible all the time.

What I would recommend now, is that for fields that you are show/hiding supplementary text that you set the supplementary text to visible and comment out the script. In other words temporarily get rid of some of the dynamic features and see if that works.

Sorry I could not be of more help. Good luck.

Off to walk the dog and clear my head of LC Designer!!!

Niall

Avatar

Level 2

Thanks a lot Niall. You did try a lot.

Do you think it because of the scripts? If so, Can you think of a alternative way to display the instructions by using other scripts or the like?

Otherwise, I just warn users not to use version 8.1 or 8.2. How do you think?

Edigo

PS: I would find some ways to clear my head out of LC Designer also, even I'm just a newbie

Avatar

Level 10

Hi Edigo,

Back again!

I don't think it is the script, because it is working in v8.1.3 for the course details, but not the course hours. It looks like the affected fields are defaulting to read only.

However in the textfields the presence=visible script works, whereas the presence=hidden does not.

I added in a new text field and it had the same problem. I have not seen this behaviour before. If you are going beyond the capabilities of a version then you will get a warning. I think it may be an issue with the dot releases of v8.

You can test the version that the user has at docReady:

if (xfa.host.version > 8.0 && xfa.host.version < 9.0)

{

     app.alert("Warning:...");

}

Bit if a dodge, but something flaky is happening in the v8.1 and v8.2 versions.

Good luck,

Niall

Avatar

Level 2

Hi Niall,

Good to hear from you back.

I just uninstalled Acrobat 9. I was thinking of trying to open the form with version 8 again but I left CDs at the office. I will do it as soon as I can.

Was any warning showing up when you added the scripts? If it's not about the scripts, I guess I don't need to use LC designer 8.0 (in version 8) to redo the whole thing. It's so tedious.

Thanks and take care,

Edigo

Avatar

Level 10

Hi,

I have a machine with LC Designer 8, but I don't have access to it until the weekend. Let me know how you get on.

I did not get any errors or warnings in LC Designer and the form worked as intended in Acrobat v9 - just not in Reader v8.1.3. I really don't think that it is the script, as this is a simple presence script. When I added the new textfield I wrote the script from scratch (I did not copy if from your field), so that I was not carrying any potential corruption - but it didn't work.

I wouldn't start redoing the form just yet, as someone else may have come against this and have a solution.

Good luck,

Niall