Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Add/Remove a text field with different properties by clicking a button

Avatar

Level 2

I have created a form that allows users to create custom quotes for our company.  I have completed most of the form with one exception.

I am trying to use Add/Remove buttons so that users can customize the 'courtesy copy' section of the letter.  This way, the user can add as many courtesy copy recipients or remove the section entirely, as needed.  I am trying to do this using text fields.  The problem I have is that the first text field has the string "CC:" in its caption field.  If the user adds a second CC recipient, I don't want the "CC:" to appear in the second text field once the user clicks the add button.

4 Replies

Avatar

Level 2

There could be many complex ways to do it,


but an easier approach would be, create a hidden field with no caption, and try repeating it's instances, instead of repeating the instance of the first field.

I hope i have answered in the right context >



~Sid

Avatar

Level 2

What about when the user wants to remove the fields including the one with the CC in the caption. Wouldnt than mean there would need to be two buttons to address each type of text field?

I am trying to post the PDF form itself but am not sure how.  Has this feature been removed?

Thanks for your help.

Avatar

Level 2

not really, when you write a script to add instances, i'm sure you would put a check on the no. of instances, i.e. at max 10 for eg.

similarly, when the delete button is clicked, it would calculare the no. of instances every time before deleting.

once the no. of instances is one , you can ask the script to hide the field with the caption.

you can definitely find samples for this , if not let me know, i will make a quick one

Avatar

Level 2

I actually figured out a way to get this to work:

1.  You create a subform.  In my file I called it "CCForm"

2.  Within CCForm you create three more subforms.  In my example I called them "CC" (which holds the text field with the CC caption), "blankCC" (which holds the text field without a caption), and "addCCButton" (which holds the "Add" button that will control the addition of new fields).

3.  CCForm, CC, and blankCC forms are set to 'Flowed'.

4.  Subforms "CC" and "blankCC" are set to "hidden"

5.  Under the binding settings for subforms "CC" and "blankCC" check "Repeat each subform for each Data Item" and "Initial Count" to 1.

6.  Create a button labeled "Courtesy Copy" outside of CCForm.

7.  In the 'click' action of the "Courtesy Copy" button, place the following Javascript:

     form1.CCForm.CC.presence="visible";
     form1.CCForm.addCCButton.presence="visible";
     form1.courtesyCopy.presence="hidden";

     What this does is make the CC textfield and 'Add CC' buttons visible after clicking the 'Courtesy Copy' button.  The 'Courtesy Copy' button will also dissappear when clicked.  Note that the blankCC subform is still hidden.

8.  In the click action of the "Add CC" button, place the following Javascript:

     //This is an if statement that determines if CC and blankCC are visible/hidden.

     //If CC is visible but blankCC is hidden, then blankCC will become visible.

     //Otherwise a new instance of blankCC will be created.

     if ((form1.CCForm.CC.presence == "visible") & (form1.CCForm.blankCC.presence == "hidden"))
    {
         form1.CCForm.blankCC.presence="visible";
    }
     else
    {
         //If both CC and blankCC are visible then a new instance of blankCC will be created

         //based on this 'else' statement.

         //Since blankCC was orginally hidden, any new instance of blankCC will be

         //hidden as well.

         //So there is also code that finds the new blankCC instance and sets it to visible

         //in this 'else' statement.

         var intNewIndex  = form1.CCForm.blankCC.instanceManager.count;

         _blankCC.addInstance();

        
         form1.CCForm.resolveNode("blankCC[" + intNewIndex + "]").presence="visible";
     }

This might be a little confusing without the actual form to look at.  It looks like Adobe removed the option to post PDF forms in the forum.  Hope it helps anyway.  Thanks for your help.