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

Single Button Show/Hide Fields

New Here ,
Nov 30, 2017 Nov 30, 2017

Copy link to clipboard

Copied

My form has a set of fields that I'd like the user to determine how many are necessary. Each block of fields is the same.

I'm trying to get the 'Add Sequence' button to display the hidden fields below the preceding fields. Currently, my button works to display 1 block of fields, but I'm

wondering if it's possible to get the 'Add Sequence' button to display a sequential hidden field each time it's clicked.

client.JPG

TOPICS
Acrobat SDK and JavaScript , Windows

Views

671

Translate

Translate

Report

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

Community Expert , Dec 04, 2017 Dec 04, 2017

Yes, this can be done, as I've described in the previous response. The key is keeping track of what's visible, as both try and I have stated

There's a couple of ways to do this. Here's an easy one.

1. Put a hidden text field on the form named "SeqNum". Default it to a value of 1.

2. Put this code in the button that shows the blocks

var nNum = ++this.getField("SeqNum").value;

if(nNum < 6)

     this.getField("Block" + nNum).hidden = false;

This code handles up to 5 blocks.

Votes

Translate

Translate
Community Expert ,
Dec 01, 2017 Dec 01, 2017

Copy link to clipboard

Copied

It's possible, but it would require using a script, as you'll need to keep track of which fields are currently visible and which ones are not.

Votes

Translate

Translate

Report

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 ,
Dec 01, 2017 Dec 01, 2017

Copy link to clipboard

Copied

I could have sworn I already answered this yesterday.  Maybe this is a re-post to another topic? Anyway, here is may answer

Yes, this is possible.  The fields need to be named in such a way that the blocks are grouped for hiding and showing, and for determining order of visibility. For example, Block1.dimension, Block1.method etc. 

Now this code will show all fields in block 1

this.getField("Block1").hidden = false;

Keep track of the sequence by looking at which blocks are hidden or shown. 

If there are page graphics and text involved, it gets more difficult. The only way to hide/show page content is with OCGs, also called layers.  There are a number of preflight tools for attaching content and fields to OCG layers (which is actually another way to show/hide form fields).  There are also ways to build a page by combining multiple pages, with each placed on a different OCG layer.

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

Votes

Translate

Translate

Report

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
New Here ,
Dec 04, 2017 Dec 04, 2017

Copy link to clipboard

Copied

Is it possible to use that code    this.getField("Block1").hidden = false; multiple times on the same button to make it so that each sequential click will hide/show the next block ?

Votes

Translate

Translate

Report

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 ,
Dec 04, 2017 Dec 04, 2017

Copy link to clipboard

Copied

Yes, this can be done, as I've described in the previous response. The key is keeping track of what's visible, as both try and I have stated

There's a couple of ways to do this. Here's an easy one.

1. Put a hidden text field on the form named "SeqNum". Default it to a value of 1.

2. Put this code in the button that shows the blocks

var nNum = ++this.getField("SeqNum").value;

if(nNum < 6)

     this.getField("Block" + nNum).hidden = false;

This code handles up to 5 blocks.

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

Votes

Translate

Translate

Report

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
New Here ,
Dec 04, 2017 Dec 04, 2017

Copy link to clipboard

Copied

Thank you! I'm fairly inexperienced with Javascript (and coding in general) this is working for me.

Would the similar code (but changed to subtract sequence numbers) under the "Remove Sequence" button work in tandem? So that let's say I've added up to Block 5, and clicking the Remove Sequence button once will now only show the top 4 blocks?

Votes

Translate

Translate

Report

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 ,
Dec 04, 2017 Dec 04, 2017

Copy link to clipboard

Copied

LATEST

Yes, just change the "++" to "--", and the if to (nNum > 0)

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

Votes

Translate

Translate

Report

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