Expand my Community achievements bar.

How to Remove the Last line of Instance in subform ?

Avatar

Former Community Member
I thought I ran across an example in this forum of how to specify which instance you want to delete from a subform but I can not find it. I can get removeInstance to work but it removes the top line and I just want it to remove the bottom or last instance that was added. I can do it if I only had 2 instances and tell it to removeInstance(1); but the form is going to be dynamic and there will be more than 2 lines when people start to use the form.
18 Replies

Avatar

Former Community Member
You need to pass the index of the instance you want to delete. So if you always want it to be the last instance it would look like this:



subform.instanceManager.removeInstance(subform.instanceManager.count - 1);



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
hello Chris,



The mentionned count method/object is not valid.



is your sample well written, or is something missing ?



thanks in advance.



Gabriel

Avatar

Former Community Member
Should be, but you have to change it to reference your subform instead of just the word subform. Here's a sample.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Hello,



I've tryed your sample, but it doesn't function.



I've got designer version 7.0 and reader 7.0.7



What version do you have ? is that the problem ?



thanks

Avatar

Former Community Member
I am using Adobe reader 7.0.3 and Adobe Designer 7.0 and the solution that I used from the example worked for me.

Avatar

Former Community Member
If it doesn't work for you, then you probably have Designer set to preview forms as static PDF's by default. Go to tools->options and change Default File Type for new forms to Dynamic. Or just save it out of Designer as a dynamic PDF and open that in Acrobat.



Chris

Adobe Enterprise Devleoper Support

Avatar

Former Community Member
I've found the reason... :-)



I'm using the designer from Acrobat professional instead of the designer from Adobe LiveCycle.



I've got Acrobat professionnal 7.0.0 and trying your sample it didn't function.



Knowing that there was a new version of Acrobat professional (7.0.7)I've installed it, and now your sample function.



I have to mention that the count method is not listed in the choice menu that appears when you're typing code inside the designer. It means that some functions have to be tryed even if the popup menu of the list of available methods doesn't mention it.. (in this case it's the count method)... :-)



There are a lot of things like that (for example there is the checkbox problems that are not good managed before Acrobat Reader 7.0.7, and Acrobat professional 7.0.7)



So I suggest to the developpers that are reading this post to always install the last version of Acrobat Reader, Acrobat Professionnal, Designer, in order that everything goes well with the product.



gpalmieri

Avatar

Former Community Member
I am using a dynamic table where a user can add or remove a row.

Is there a way to get a handle on the current row for removal part?



currently I have a table row with two buttons in first column (add and remove)

on click event that I have for the remove button is:

subForm.Table.Row.instanceManager.removeInstance(1);



This does not remove the row where the button is ...

Avatar

Former Community Member
Also I tried the following but not getting the result I want



subForm.table.Row.instanceManager.removeInstance(subForm.table.Row.instanceManager.index);

Avatar

Former Community Member
I am also having the same request/issue as Vikram above. I'd like to remove a particular row in-between the rows I've added (usually the row where my cursor is). At times, if I've added 10 rows, I might need to delete out row 8 above - currently it is only set to remove from the bottom up (so it deletes #10 first, then 9, etc.)



Any suggestions?

Avatar

Former Community Member
Hi Gretchen,



I solved this by using parent.index in removeInstance

basically my table is in a sub-form and the first cell of the row I have another sub-form where I have 2 buttons "Add" & "Remove"



onclick event of the "Remove" button has this code

tblT2.Row.instanceManager.removeInstance(this.parent.parent.index);



the reason I have to do parent twice cause my buttons are in sub-form, which is in a cell of a row that has index that we want to remove.



This works for me.



Hopr this helps ...

Avatar

Former Community Member
Thanks Vikram!



I pasted your code into the add/remove instance of my click event. So far, so good. One problem - my table is setup with one row (named Row1) and in the binding tab, is set at a minimum of 1, max of 100 and initial count of 6. So when I click the PDF preview, 6 rows display in view.



When I try clicking my remove (-) button, it continues removing the very top row (my Row1) - and NOT any of the other rows where my cursor is. Worst case scenario and I can't get the rows to remove where my cursor is, I'd like it to remove from the bottom up (starting with that initial #6).



Hope this makes sense! If you'd like to provide further instructions by email, I'm at: gretchen.payne@wch-rcc.com.



Thank you!!

Avatar

Former Community Member
Do you need 6 rows to appear when form loads?

If not you can uncheck "Repeat Table for each data Item"



I can send you a sample that might help.

Avatar

Former Community Member
This is mostly in question to Vikram's helpful posts...but I'm still stuck on one issue. I've been able to get my table set up to where I can add/delete individual rows - however, I'm having issues with the "adding" feature.



When I click to remove a particular row, it will remove THAT row only (this is good; it's doing what I want). HOWEVER, while I can add a row, it doesn't add it in-between rows or wherever I want; it usually tacks one on at the bottom of my table. For example: I have 5 rows that display when the form opens. Depending on which row you select (say row 3), it will remove just row 3 and keep the others. BUT, when I go to add, despite being in row 3, it adds the new row at the bottom of my table (below row 5), when in actuality, I needed it beneath row 3.



I'm sorry this sounds so confusing - but streamlined - I need the ability to add beneath the row I am currently in. My scripts seem to be setup just fine....but maybe my adding feature is missing something???



Any suggestions?

Avatar

Former Community Member
While subForm.table.Row.instanceManager.removeInstance(n) always remove row n from the table (count begin 0). If I want remove the last row every time I click on a button use the script, please how to get the index n of the last row of the table?

Avatar

Former Community Member
go like this.



var n = subForm.table.Row.instanceManager.count - 1//because it's 0 based



then:



subForm.table.Row.instanceManager.removeInstance(n)

Avatar

Former Community Member
Hi Gretchen,

You can use the moveInstance() method for ur row addition issue.



Subform1.table.row.instanceManager.moveInstance(from_index,to_index);



Replace "from_index" and "to_index" with appropriate row index values.

Avatar

Former Community Member
Hi,



I want to add a row instance in a dynamic table thats already mapped to a xsd file. Meaning: On previewing the pdf, the table will already be populated with some data. Apart from this, the user can click on the add button to add a row instance to this table.



Now my problem here is, when my table rows are not mapped to xsd file, the add row instance function works properly. But when the xsd is mapped to the table row, the function doesnt work.



the script that i use for Add button is:



SubForm.Table1.Row.instanceManager.addInstance(1)



Please help me out in cracking this!