Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

duplicate a set of rows in a table via a button click event

Avatar

Former Community Member

I created a set of tables - each table has a cell with its Title, then three rows, each having a checkbox with some related text.

I did it like this because I couldn't figure out any other way to do it without having the longest heirarchy in the world.

Anyway, after setting up about 20 tables with their specific Titles and their checkbox rows, I need to allow users to be able to Add new Titles (tables), should they come up.

On the last "table set" I want to have an Add button and then a remove button.

I know how to add and remove a ROW, but can I add and remove a Table? a Set of rows?

Can anyone direct me? I have 3 forms that will all use this feature and I don't want to fail.

Thanks!

Marla

13 Replies

Avatar

Level 10

Hi Maria, you can do this quite easily by wrapping the last table in a subform. You then treat this subform as a repeating object in the Object > Binding palette. addInstance and removeInstance can then be applied to the subform. If you have a look at the Building Dynamic Tables solution at www.assuredynamics.com the last table uses subforms. Niall

Avatar

Former Community Member

Hi Niall,

thanks for your reply. I did wrap the last table in a subform (flowed) and then set as a repeating object in the binding pallette.

However the addInstance and removeInstance will be trickier as I need to be able to add and remove 3 rows at the same time - these 3 rows always stay together because they have fields for information that people need to enter.

Using the script from the last table, I couldn't quite figure out how to include the whole table and not just a row into the script.

Can you help me to figure this out?

Thanks

Marla

Avatar

Former Community Member

Hi again Niall,

I played around with the scripting and was able to get the 'add' button to add all 3 of the rows at once!

here is my script:

// '_' is shorthand for instanceManager, eg '_rowSubform'

_SubformExtra.addInstance(true);

// if the edit mode is active, deactivate it

// also want to have new subform in non-edit mode

editRow1.execEvent("click");

editRow2.execEvent("click");

editRow3.execEvent("click");

Now I need to figure out how to be able to get a Remove button to remove the same, in case the user wants to do that.

Can you shed light on that process?

Thanks!

Marla

Avatar

Level 10

Hi Maria, I am out at the moment, so don't have access to examples. However if you look at the reset button in the Building Dynamic Tables example, you will see how I use a loop to remove rows. Also there is a Two-Way Binding example on the website where the add and remove buttons work on corresponding rows on two separate tables. I suspect that you can achieve what you are looking for, but it will take a bit of thought and script. Hopefully the examples will help. Niall

Avatar

Level 10

Tá fáilte romhat!

Go n-éirí an t-ádh leat le do foirm LiveCycle.

Slán,

Niall

Avatar

Former Community Member

Yes, thank you, i need it!

having no luck with the removal of the table cells... can add them just fine!

still working it out..

Slán go fóill!

Avatar

Level 10

Dia duit Maria,

Can you share the form, or the part you are having trouble with? If you can, upload it to a file sharing site such as Acrobat.com and then post the published URL here.

Slán,

Niall

Avatar

Former Community Member

Dia is Muire dhuit Niall.

I'll have to do this tomorrow as I am preparing to leave for the day.

Oiche mhaith!

Marla

Avatar

Former Community Member

Good Morning Niall,

I'm sorry, I cannot share the form because it is a company-proprietary form.

Can you tell me if there is a method for adding and removing a section that I could use to add and remove this 3-rowed table section?

Although, I was able to adapt the script to make the 3 rows add to the end of the table, I can't seem to adapt the script to remove them. See the examples of script below:

Here is my script to add them:

form1.SubformExtra.Tableaddothter.Row1.AddButton::click - (JavaScript, client)

// '_' is shorthand for instanceManager, eg '_rowSubform'

_SubformExtra.addInstance(

true);

// if the edit mode is active, deactivate it

// also want to have new subform in non-edit mode

editRow1.execEvent("click");

editRow2.execEvent("click");

editRow3.execEvent("click");

--------

The following script is used to remove an instance on ONE row only.

form1.SubformTeamAttendance.subformTA.Table1.Item[0].RemoveRow::click - (JavaScript, both)

// remove this row by accessing its index within the set of 'Item' row instances of the parent table

this.parent.parent._Item.removeInstance(this.parent.index);

xfa.form.recalculate(1);

-------

This is the script I added to remove the 3 rows, but it doesn't work; I am only a javescript novice... as you can tell, I patterned it on the add script.:

form1.SubformExtra.Tableaddothter.Row3.RemButton::click - (JavaScript, client)

 

// '_' is shorthand for instanceManager, eg '_rowSubform'

_SubformExtra.removeInstance(

true);

// if the edit mode is active, deactivate it

// also want to have new subform in non-edit mode

editRow1.execEvent("click");

editRow2.execEvent("click");

editRow3.execEvent("click");

Avatar

Level 10

Hi Maria,

Sorry for the delay in getting back to you.

The parameter for the removeInstance is not true. You need to pass through the instance number of the repeating object that you want to remove.

Similar to the script removing the songle row. This uses "this.parent.index" to indicate to Acrobat/Reader to remove the instance that contains the button that was clicked.

So you would need to specify which instance of SubformExtra you want to remove. If you only have one instance, then change "true" to "0".

Hope that helps,

Niall

Avatar

Former Community Member

Dia Dhuit!  Niall,

thanks for getting back to me.

I actually found or came up with

this.resolveNode("SubformAddSection").instanceManager.removeInstance (this.parent.index);

xfa.form.recalculate(1);

which does remove the 3-row set.

But it doesn't let me select which added set to remove. If I Add 3 rows and call them 1, 2, 3, and 4, and hit ANY remove row button, the first instance of the set is removed.

Even worse, for some reason, when entering LOTS of text in the expanding Comments sections, the rows cover the footers, insert extra blank pages and so on. Any ideas on this new problem a co-worker brought to my attention?

This all used to work for me. I think I have to recreate the entire form. I think I have a big mess here.

Thanks if you can shed any further light on this...

Avatar

Level 10

Dia duit Maria,

Firstly if we deal with the removeInstance. It depends on which object you are using for the script. If the parent.index of the object is '0', then it will always remove the first instance.

When you have a repeating object, the instances use a zero-based numbering system. So 'SubformAddSection[0]', 'SubformAddSection[1]', 'SubformAddSection[2]' and so on.

The script that you are using would normally be associated with a button inside 'SubformAddSection'. If the button is in fact inside another subform inside 'SubformAddSection', then you would need to use (note 'this.parent.parent.index' to get to the particular instance of 'SubformAddSection'):

this.resolveNode("SubformAddSection").instanceManager.removeInstance(this.parent.parent.index);

In addition, I don't think you will need to resolve the node, but it may depend if you have unnammed pages and subforms.

Without seeing the form it is difficult to be sure.

In relation to the footer, have a look at this example that shows how you can adjust the size of the content area on the Master Page, so that footers are outside of the content area. http://bit.ly/ia4o7m

Slán,

Niall

Assure Dynamics