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.

new instance problem

Avatar

Former Community Member

hello,

I have a ES4 form that I am working. I have added a row above a hidden table. This row has a button to open "show" a hidden table.

When clicked the table expands. the table has many cells. One cell has buttons to add new instance or hide the table itself. The add new instance upon click is not functioning. This is what breaks.

The hide table works fine.

If I try the same thing but with a table that is not originally hidden then it works fine. New instances occur. I need to reduce clutter on my form so it would benefit me to have it initially be hidden but then the add new instance has to work.

I use the action builder to add the javascript.

any advice?

thanks,

-Z

10 Replies

Avatar

Former Community Member

this is the code for the add table button:

form1.DCtable.DCtablerow1.DCtableacell1.DCtableadd::click - (JavaScript, client)

//+ GENERATED - DO NOT EDIT (ID:F0FA29C1-D483-4F69-9B04-E7E69AD9FB64 CRC:2073942169)

//+ Type: Action

//+ Result2: SetPresence("$Node2","visible")

//+ Result1: AddInstance("$Node2")

//+ Node2: form1[0].DCtable[0]

//+ Node1: form1[0].DCtable[0].DCtablerow1[0].DCtableacell1[0].DCtableadd[0]

//+ Condition1: Button("$Node1","click")

//+ ActionName: DCtableadd.click

this.resolveNode('form1._DCtable').addInstance(1);

if (xfa.host.version < 8) {

  xfa.form.recalculate(1);

}

this.resolveNode("DCtable").presence = "visible";

//-

Avatar

Level 10

Hi,

don't get caught by adding new instance on hidden objects. Adding new instances copies the object as it is initially created with the form.

So if your table is initially hidden in the form and you add an instance to it, you will have to get that instance and put it visible

Avatar

Former Community Member

do I add this to what I had in there or do I replace the last part with this?

Avatar

Former Community Member

i tried replacing it and it is still broken.

this is the key part, right?

(DCtable[" + (_DCtable.count - 1).toString() + "])

Avatar

Level 10

Hi,

Yes this line is to get the last instance of the table and then you set it to visible.

This code is for the purpose of adding a new instance of a Table only if the table is set to hidden by default.

If you are trying to add an instance of a row inside the table, this is not the right reference_syntax, you would have to addInstance to the Row1 inside the table.

Also make sure that you have the right reference to get access to the DCtable

Avatar

Level 10

Could you please take a screenshot of the hierarchy of the table and show it to me.

Identify as well which object you are trying to add an instance too.

You might have to add an instance to the row instead of the table.

If you are really trying to add an instance to the table you must set its maximum occurrence if there is none.

Avatar

Former Community Member

here is the hierarchy:

heirarchy.png

here is the table:

DCtable.png

here is the add button:

DCtableadd.png

the same arrangement works fine if the table is initially visible. I only run into the problem when I want it to be hidden in the begining. having it be hidden will be the key to making the form manageable.

It may end up with forty headings with forty hidden tables with the ability to add new instances of any of them.

Also to hide half of them if they are not applicable.

The hide works fine. I had problems with remove an instance but I found that hide works fine. Would that cause problems down the line?

Thank you for taking the time to give it look.

-Z

Avatar

Level 10

Hi sorry about, that seems like there was some syntax error in my code, it should be working with the following

Avatar

Former Community Member

It works! thank you so much!  I appreciate you for taking the time