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

Hidden Fields Appear at Specific Coordinates

Explorer ,
Jan 20, 2021 Jan 20, 2021

I have a fillable form that has several hidden fields. When a choice is made from one of the drop down lists, then one of the hidden fields will appear. As there are several drop downs that have the same options, what I am hoping to do is have the hidden field appear at a specific set of coordinates on the form. If the user chooses the same option from one of the other drop downs, then the same hidden field may appear at a different set of coordinates. Does that make sense? 

 

I have been shooting in the dark. Making the field appear is not the problem. I am using the following to make the field appear. I don't know how to get it to appear at specific coordinates like x=510 and y=77 or oCoords: [510,77,580,59]; etc.:

 

this.getField("Test").display = display.visible;

 

Thoughts?

TOPICS
Create PDFs , How to , JavaScript , PDF forms
914
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 ,
Jan 20, 2021 Jan 20, 2021

You can set the property "rect".

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
Explorer ,
Jan 20, 2021 Jan 20, 2021

I'm confused how to use rect. Isn't that normally used to draw a rectangle? I already have a predesigned field ready, I just need have it appear at the right coordinates. What coding would you use in this case?

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 ,
Jan 20, 2021 Jan 20, 2021

You can read and set it with this.getField("Test").rect

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
Explorer ,
Jan 28, 2021 Jan 28, 2021

So, I didn't get a specific answer from the thread that solved my issue, but I did find a work around using the this.addField and then referencing the field I wanted to appear and the coordinates where I wanted.

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 ,
Jan 28, 2021 Jan 28, 2021

The answer above is the correct one. If you used addField then you've done the same thing as was suggested, ie. to set the rect property of the field. In addField it's the last parameter, but you can also use it on an existing thing, like this:

this.getField("Text1").rect = [x1, y1, x2, y2];

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
Explorer ,
Jan 28, 2021 Jan 28, 2021

I changed the code to read how you had it, but the hidden field "Luca" still does not appear. I know I'm not the greatest at this, but I still can't see what I'm missing. Here is what I put:

 

this.getField("Luca").rect = [144,474,306,424];

 

I need the field "Luca" to go from hidden to visible at the specified coordinates when Luca is chosen from the drop down and then I need it to go back to hidden if another option is chosen in the same drop down field.

 

Sorry for the headache.

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 ,
Jan 28, 2021 Jan 28, 2021

You need to do a little debug to figure things out. To do this use the the console window to run sample code for placing the field.  i.e. make the "Luca" field visible. Open the console window. Enter the code for changing the rectangle, then run it. See what happens. enter different coordinates and run the code. This is how code development is done. You don't just enter large amouts of code that you have no idea of how it works. You create little tests to figure it all out.

You'll find a tutorial here on using the Console Window.

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

 

 

 

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
Community Expert ,
Jan 28, 2021 Jan 28, 2021
LATEST

You must also change the property display. 

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 ,
Jan 28, 2021 Jan 28, 2021

So do you then delete the field when you want it hidden? This is a really bad plan. Bernd gave you the correct and simple answer. Just change the "rect" property of the field. 

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
LEGEND ,
Jan 28, 2021 Jan 28, 2021

There's no need to guess what "rect" does, it's in the manual. You will always need to look up a method or property before coding it...

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