Expand my Community achievements bar.

SOLVED

Need some help getting add/remove field buttons working

Avatar

Level 1

Someone here on the forums had previously assisted me with getting a button set up on a form that would add an additional text field to a form.  I now need a separate button created that will delete a text field in case too many were added.  I am hoping that someone can assist me with this since my XML knowledge is pretty much nil.  It doesn't look like I can upload files to the forum here, so I am going to attempt to paste my code.  I just need to get the "-" button to subtract a row.  Thanks in advance for the assistance.

-Chris

<?xml version="1.0" encoding="UTF-8"?>

<?xfa generator="AdobeLiveCycleDesignerES_V8.2.1.4029.1.523496" APIVersion="2.8.9029.0"?>

<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/" timeStamp="2010-06-28T16:04:04Z" uuid="081329f3-4914-4dde-87ae-75a83da8434e">

<template xmlns="http://www.xfa.org/schema/xfa-template/2.6/">

   <?formServer defaultPDFRenderFormat acrobat8.1static?>

   <subform name="form1" layout="tb" locale="en_US">

      <pageSet>

         <pageArea name="Page1" id="Page1">

            <contentArea x="19.05mm" y="12.7mm" w="190.5mm" h="266.7mm"/>

            <medium stock="default" short="612pt" long="792pt"/>

            <?templateDesigner expand 1?></pageArea>

         <?templateDesigner expand 1?></pageSet>

      <subform w="7.5in" h="10.5in" name="Page1">

         <subform w="174.625mm" y="79.377mm" name="Current_Objectives" layout="tb">

            <subform w="174.625mm" h="9.522mm" name="Objective">

               <field name="txt_currobj" minH="8.263mm" w="174.625mm">

                  <ui>

                     <textEdit multiLine="1">

                        <border>

                           <?templateDesigner StyleID aped3?>

                           <edge stroke="lowered"/>

                        </border>

                        <margin/>

                     </textEdit>

                  </ui>

                  <font size="11pt" typeface="Verdana"/>

                  <margin topInset="1mm" bottomInset="1mm" leftInset="1mm" rightInset="1mm"/>

                  <para vAlign="middle"/>

                  <caption reserve="7.76mm">

                     <para vAlign="middle"/>

                     <value>

                        <text>1.</text>

                     </value>

                     <font size="11pt" typeface="Verdana"/>

                  </caption>

                  <event activity="initialize" name="event__initialize">

                     <script contentType="application/x-javascript">this.caption.value.text.value = (this.parent.index + 1) + "."

</script>

                  </event>

               </field>

               <occur max="-1"/>

               <?templateDesigner expand 1?></subform>

            <field h="5.08mm" name="curr_obj_add_line" w="5.08mm">

               <ui>

                  <button highlight="push"/>

               </ui>

               <font typeface="Arial"/>

               <caption>

                  <value>

                     <text>+</text>

                  </value>

                  <para hAlign="center" vAlign="middle"/>

                  <font typeface="Arial"/>

               </caption>

               <border hand="right">

                  <edge stroke="raised"/>

                  <fill>

                     <color value="212, 208, 200"/>

                  </fill>

                  <?templateDesigner StyleID apbx2?></border>

               <bind match="none"/>

               <assist>

                  <toolTip>Add an item</toolTip>

               </assist>

               <event activity="click" name="event__click">

                  <script contentType="application/x-javascript">

_Objective.addInstance(1)

</script>

               </event>

            </field>

            <field h="5.08mm" name="curr_obj_del_line" w="5.08mm">

               <ui>

                  <button highlight="push"/>

               </ui>

               <font typeface="Arial"/>

               <caption>

                  <value>

                     <text>-</text>

                  </value>

                  <para hAlign="center" vAlign="middle"/>

                  <font typeface="Arial"/>

               </caption>

               <border hand="right">

                  <edge stroke="raised"/>

                  <fill>

                     <color value="212,208,200"/>

                  </fill>

                  <?templateDesigner StyleID apbx2?></border>

               <bind match="none"/>

               <assist>

                  <toolTip>Delete an item</toolTip>

               </assist>

               <event activity="click" name="event__click">

                  <script contentType="application/x-javascript">

_Objective.deleteInstance(1)

</script>

               </event>

            </field>

            <?templateDesigner expand 0?></subform>

         <?templateDesigner expand 1?></subform>

      <desc>

         <text name="version">8.2.1.4029.1.523496.503679</text>

      </desc>

      <?templateDesigner expand 1?></subform>

   <?templateDesigner DefaultLanguage FormCalc?>

   <?templateDesigner DefaultRunAt client?>

   <?acrobat JavaScript strictScoping?>

   <?templateDesigner Zoom 100?>

   <?templateDesigner Grid show:1, snap:1, units:0, color:ff8080, origin:(0,0), interval:(125000,125000)?>

   <?templateDesigner FormTargetVersion 26?>

   <?templateDesigner SaveTaggedPDF 1?>

   <?templateDesigner SavePDFWithEmbeddedFonts 1?>

   <?templateDesigner Rulers horizontal:1, vertical:1, guidelines:1, crosshairs:0?></template>

<config xmlns="http://www.xfa.org/schema/xci/2.6/">

   <agent name="designer">

      <destination>pdf</destination>

      <pdf>

         <!--  [0..n]  -->

         <fontInfo/>

      </pdf>

   </agent>

   <present>

      <!--  [0..n]  -->

      <pdf>

         <!--  [0..n]  -->

         <version>1.7</version>

         <adobeExtensionLevel>1</adobeExtensionLevel>

      </pdf>

      <common/>

      <script>

         <runScripts>server</runScripts>

      </script>

      <xdp>

         <packets>*</packets>

      </xdp>

   </present>

   <?originalXFAVersion http://www.xfa.org/schema/xci/2.8/?></config>;

<localeSet xmlns="http://www.xfa.org/schema/xfa-locale-set/2.6/">

   <?originalXFAVersion http://www.xfa.org/schema/xfa-locale-set/2.6/?>;

   <locale name="en_US" desc="English (United States)">

      <calendarSymbols name="gregorian">

         <monthNames>

            <month>January</month>

            <month>February</month>

            <month>March</month>

            <month>April</month>

            <month>May</month>

            <month>June</month>

            <month>July</month>

            <month>August</month>

            <month>September</month>

            <month>October</month>

            <month>November</month>

            <month>December</month>

         </monthNames>

         <monthNames abbr="1">

            <month>Jan</month>

            <month>Feb</month>

            <month>Mar</month>

            <month>Apr</month>

            <month>May</month>

            <month>Jun</month>

            <month>Jul</month>

            <month>Aug</month>

            <month>Sep</month>

            <month>Oct</month>

            <month>Nov</month>

            <month>Dec</month>

         </monthNames>

         <dayNames>

            <day>Sunday</day>

            <day>Monday</day>

            <day>Tuesday</day>

            <day>Wednesday</day>

            <day>Thursday</day>

            <day>Friday</day>

            <day>Saturday</day>

         </dayNames>

         <dayNames abbr="1">

            <day>Sun</day>

            <day>Mon</day>

            <day>Tue</day>

            <day>Wed</day>

            <day>Thu</day>

            <day>Fri</day>

            <day>Sat</day>

         </dayNames>

         <meridiemNames>

            <meridiem>AM</meridiem>

            <meridiem>PM</meridiem>

         </meridiemNames>

         <eraNames>

            <era>BC</era>

            <era>AD</era>

         </eraNames>

      </calendarSymbols>

      <datePatterns>

         <datePattern name="full">EEEE, MMMM D, YYYY</datePattern>

         <datePattern name="long">MMMM D, YYYY</datePattern>

         <datePattern name="med">MMM D, YYYY</datePattern>

         <datePattern name="short">M/D/YY</datePattern>

      </datePatterns>

      <timePatterns>

         <timePattern name="full">h:MM:SS A Z</timePattern>

         <timePattern name="long">h:MM:SS A Z</timePattern>

         <timePattern name="med">h:MM:SS A</timePattern>

         <timePattern name="short">h:MM A</timePattern>

      </timePatterns>

      <dateTimeSymbols>GyMdkHmsSEDFwWahKzZ</dateTimeSymbols>

      <numberPatterns>

         <numberPattern name="numeric">z,zz9.zzz</numberPattern>

         <numberPattern name="currency">$z,zz9.99|($z,zz9.99)</numberPattern>

         <numberPattern name="percent">z,zz9%</numberPattern>

      </numberPatterns>

      <numberSymbols>

         <numberSymbol name="decimal">.</numberSymbol>

         <numberSymbol name="grouping">,</numberSymbol>

         <numberSymbol name="percent">%</numberSymbol>

         <numberSymbol name="minus">-</numberSymbol>

         <numberSymbol name="zero">0</numberSymbol>

      </numberSymbols>

      <currencySymbols>

         <currencySymbol name="symbol">$</currencySymbol>

         <currencySymbol name="isoname">USD</currencySymbol>

         <currencySymbol name="decimal">.</currencySymbol>

      </currencySymbols>

      <typefaces>

         <typeface name="Myriad Pro"/>

         <typeface name="Minion Pro"/>

         <typeface name="Courier Std"/>

         <typeface name="Adobe Pi Std"/>

         <typeface name="Adobe Hebrew"/>

         <typeface name="Adobe Arabic"/>

         <typeface name="Adobe Thai"/>

         <typeface name="Kozuka Gothic Pro-VI M"/>

         <typeface name="Kozuka Mincho Pro-VI R"/>

         <typeface name="Adobe Ming Std L"/>

         <typeface name="Adobe Song Std L"/>

         <typeface name="Adobe Myungjo Std M"/>

      </typefaces>

   </locale>

</localeSet>

<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.2.1-c041 52.337767, 2008/04/13-15:41:00        ">

   <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

      <rdf:Description xmlns:xmp="http://ns.adobe.com/xap/1.0/" rdf:about="">

         <xmp:MetadataDate>2010-06-28T16:04:04Z</xmp:MetadataDate>

         <xmp:CreatorTool>Adobe LiveCycle Designer ES 8.2</xmp:CreatorTool>

         <xmp:ModifyDate>2010-06-28T11:28:54-04:00</xmp:ModifyDate>

         <xmp:CreateDate>2010-06-18T11:45:23-04:00</xmp:CreateDate>

      </rdf:Description>

      <rdf:Description xmlns:pdf="http://ns.adobe.com/pdf/1.3/" rdf:about="">

         <pdf:Producer>Adobe LiveCycle Designer ES 8.2</pdf:Producer>

      </rdf:Description>

      <rdf:Description xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/" rdf:about="">

         <xmpMM:DocumentID>uuid:081329f3-4914-4dde-87ae-75a83da8434e</xmpMM:DocumentID>

         <xmpMM:InstanceID>uuid:4d9ea5d0-fbf1-4be5-8aa5-b9c828a765e9</xmpMM:InstanceID>

      </rdf:Description>

      <rdf:Description xmlns:dc="http://purl.org/dc/elements/1.1/" rdf:about="">

         <dc:format>application/pdf</dc:format>

      </rdf:Description>

      <rdf:Description xmlns:desc="http://ns.adobe.com/xfa/promoted-desc/" rdf:about="">

         <desc:version rdf:parseType="Resource">

            <rdf:value>8.2.1.4029.1.523496.503679</rdf:value>

            <desc:ref>/template/subform[1]</desc:ref>

         </desc:version>

      </rdf:Description>

   </rdf:RDF>

</x:xmpmeta>

<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">

   <annots/>

</xfdf></xdp:xdp>

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

It is difficult to see from the XML Source what is going on. There are file sharing sites like Acrobat.com or YouSendIt.com where you can upload the files.

In any case I see the add button, so the delete row button would look like:

_Objective.removeInstance(this.parent.index); 

The underscore is shorthand for instanceManager. I suspect that Objective is the repeating element. It is easier to include the delete row button in the repeating row, that way the user can select which row they want to delete.

There is a sample here: https://acrobat.com/#d=tdpzltrl25yU2PkvgaQO9w

Look in the click event of the 'X' button.

Good luck,

Niall

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

Hi,

It is difficult to see from the XML Source what is going on. There are file sharing sites like Acrobat.com or YouSendIt.com where you can upload the files.

In any case I see the add button, so the delete row button would look like:

_Objective.removeInstance(this.parent.index); 

The underscore is shorthand for instanceManager. I suspect that Objective is the repeating element. It is easier to include the delete row button in the repeating row, that way the user can select which row they want to delete.

There is a sample here: https://acrobat.com/#d=tdpzltrl25yU2PkvgaQO9w

Look in the click event of the 'X' button.

Good luck,

Niall

Avatar

Level 1

Excellent!  Thanks very much.  That definitely got me the button I needed and it works pretty well.  I do have one issue with it though.  If I add a few lines with the + button and then delete one with the new - button, it deletes line # 2 instead of the last one.  Is there an easy way to fix this?  I have uploaded the file here.  I really appreciate the assistance.

-Chris

Avatar

Level 10

Hi,

The (1) is incorrect for the removeInstance.

In the addInstance script the (1) is for "true" - merge the new instance with the data model.

In the removeInstance you need to specify which instance you want to remove.

So in your button the script would look think this:

var vCount = _Objective.count - 1;


_Objective.removeInstance(vCount);

This counts the number of instances and then subtracts 1, because the instances are zero based.

I have also added a button within the repeating instance, which allows the user to select the instance they want to remove.

_Objective.removeInstance(this.parent.index);

The this.parent.index is telling Acrobat that the instance to delete is the one that the button is in.

Form is here: https://acrobat.com/#d=nn2Ubo6tq5TDEcrtnz-SCg

Good luck,

Niall

Avatar

Level 1

That is perfect.  Thanks so much for your time.  I really appreciate it.