6 Replies Latest reply on Dec 4, 2017 11:11 AM by Thom Parker

    Single Button Show/Hide Fields

    ryanm45904805

      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

        • 1. Re: Single Button Show/Hide Fields
          try67 MVP & Adobe Community Professional

          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.

          • 2. Re: Single Button Show/Hide Fields
            Thom Parker Adobe Community Professional

            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.

            1 person found this helpful
            • 3. Re: Single Button Show/Hide Fields
              ryanm45904805 Level 1

              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 ?

              • 4. Re: Single Button Show/Hide Fields
                Thom Parker Adobe Community Professional

                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.

                • 5. Re: Single Button Show/Hide Fields
                  ryanm45904805 Level 1

                  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?

                  • 6. Re: Single Button Show/Hide Fields
                    Thom Parker Adobe Community Professional

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