Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Hide a button when a pdf opens?

Avatar

Level 1

Greetings all,

    

I'm creating a pdf form using LiveCycle 8.0 that needs to hide or disable (either would be fine) a button when the pdf is first opened, depending on whether there is user-entered text present in a field on the form already. This would be due to users opening it, entering data in the text field, and then having saved it previously.

Here is the javascript that I have tried so far.

var k = form1.Table.subject.Paragraph.subject_name.rawValue;

if (k.length != 0){

form1.Button1.presence = "Hidden";

form1.Button1.access = "readOnly";

}

I've put the code into the 'docReady', 'form:ready' and 'layout:ready' events of my form, but when I open the form after saving some text in the text field, the button is still visible upon closing and re-opening the form.

The weird part is, if I set the 'Default' property of the text box to any non null value and test it in the Preview tab, it works!

It seems as though the Default property is set (and detected) by the events above before any user-entered (and previously saved) text is loaded into the text box fields on a form, so the events that I'm checking don't seem to be catching the user entered text at the point that they fire.

Basically, I'm asking how do I check for user-entered text (i.e. not part of the 'default' property of the text field) in a text field and then disable or hide a button on the form upon the pdf being opened?

What events should have my code in them?

If it is 'layout:ready', which one?  The one for the form, the text field, or the button I want to hide?

Thanks in advance for all replies,

DJF

1 Accepted Solution

Avatar

Correct answer by
Level 1

Thanks all for the replies.


I solved the problem.  My script just wasn't running.  I forgot to open the form in Acrobat Pro and do an 'Advanced->Enable Usage Rights in Adobe Reader'.  As soon as I did that everything ran fine.

Thanks again the help!

DJF

View solution in original post

3 Replies

Avatar

Level 10

Hi,

For something like this I would use docReady. It is a great event. It is one of the last to fire as the form renders and only fires once.

I would expect your script to work. Maybe drop the .access line, as the button is already hidden.

Also check the object references. There doesn't appear to be any reference to a "page".

Lastly, when Previewing or open in Acrobat use the JavaScript Console (Control+J) to see if there are any errors, as the form loads:

Javascript Console.png

Niall

Avatar

Level 10

Few things to check.

1) Make sure your form is saved as Dynamic PDF.

2) Under File -> Form Properties menu, under Default tab, make sure the "Preserve Scripting changes to form when Saved" is set to Automatically.

3) Place a messageBox command to see what is the actual value of the field at the time of opening the form.

          xfa.host.messageBox("The saved value is " + k);

You can place the code in the initialize event of the field.

Thanks

Srini

Avatar

Correct answer by
Level 1

Thanks all for the replies.


I solved the problem.  My script just wasn't running.  I forgot to open the form in Acrobat Pro and do an 'Advanced->Enable Usage Rights in Adobe Reader'.  As soon as I did that everything ran fine.

Thanks again the help!

DJF