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.
SOLVED

Javascript to remove subform

Avatar

Former Community Member

Hi!

Can somebody please tell me what am I doing wrong and why the subform is not removed when I push "Delete position" button?

I am using command _Subformname.removeInstance(1);

Is this correct. Please help!

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Set the "min" property on each sub-form to "0" (zero) before doing a removeInstance and set the removeInstance arguement to "0" (zero). The attached contains the updated "click" event scripts as shown for Subform1, below.

// form1.Subform1.Subform1.Button1::click - (JavaScript, client)

form1.Subform1._Subform1.occur.min = "0";

form1.Subform1._Subform1.removeInstance(0);

Steve

View solution in original post

17 Replies

Avatar

Correct answer by
Former Community Member

Set the "min" property on each sub-form to "0" (zero) before doing a removeInstance and set the removeInstance arguement to "0" (zero). The attached contains the updated "click" event scripts as shown for Subform1, below.

// form1.Subform1.Subform1.Button1::click - (JavaScript, client)

form1.Subform1._Subform1.occur.min = "0";

form1.Subform1._Subform1.removeInstance(0);

Steve

Avatar

Former Community Member

Thank you very much for your answer.  Practically my question is answered.

Meanwhile, I have changed my mind and I will copy the subform. What I don't know is how to remove the curent subform.

With my script, or even if I use your script, it always delete the position under it, not the current position.

To be more clear; how do I write in javascript remove_current_subform ?

Avatar

Former Community Member

Once you remove a subform instance, do you want the subform instances that follow the deleted subform to move up the list or remain in place?

Avatar

Former Community Member

I want to move up in place of the deleted subform.

Avatar

Former Community Member

Can someone plese help

. Or it is not possible to do it?

Avatar

Level 10

Use the following code in the delete button.

Subform1.instanceManager.removeInstance(this.parent.instanceIndex);

See the modified PDF attached.

Nith

Avatar

Former Community Member

Thank for your answer but something is not right.

I am also using an image in the subform. Using the comand that $Nith$ seems that the subform is deleted but the image field is not updated.

From the attached file is we delete the second subform we should obtain in the first page 2 subforms containing 1st image.

Seems that this is not happening.

Please help.

Avatar

Level 10

Am also struggling to dynamically find the current instance;

Just moved your static images to a separate subform and it works now. See the updated PDF.

Nith

Avatar

Former Community Member

Man, thank you for your help but is still not working.

From attached file, second page, please delete position in the middle.

Maybe some staff member can help me.

Avatar

Former Community Member

Just tried your form here and it seems to be working fine. Can you describe the steps to duplicate the issue?

Paul

Avatar

Former Community Member

Please see my notes in second page of file notes.pdf. The pdf created in livecycle is dinamic-pdf.pdf

Avatar

Former Community Member

OK I think I have it ......when you delete the instance you shoudl be using index and not indexInstance. Also I added a command to force a redraw of the screen .....this is the relayout command that you see that I have added to the delete script. Is this working as expected now?

Paul

Avatar

Former Community Member

Thank you very much to all of you. Problem solved.

Is it too much to ask is pls somebody tell me count 1st position as 1 and not 0, and then the 2nd to be 2, the 3rd to be 3 and so on ...?

P.S. I accidentally set the correct answer as the second post. Please move the corect answer to the one avobe this post.

Avatar

Former Community Member

What is being displayed is the index of the subform that is being displayed and that is 0 based. If you want to use it as an indicator to your user then simply add 1 to the expression.

Paul

Avatar

Level 4

Hi,  I tried this example and when I remove an instance and then save, then reopen the pdf it did not stay removed.  I've tried this in Adobe Reader 9.1 with extensions.  I'm working on a similiar form with this situation and it's not working either.  Can you help.  Thanks

Avatar

Level 4

BTW - my question is in regards to the test_SW sample.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----