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.

Change caption for repeating subforms

Avatar

Level 7

Hi,

Here is a script on change event to change the caption of the repeating field:

form1.Page1.personalInfo.

Default caption is: Manager

My problem it is that works only for the first instant.

Does not work for the second, third and so on...instances

Any help

Thank you very much 

switch (xfa.event.newText)

{

case "A":

xfa.resolveNode("form1.Page1.personalInfo.caption.value.#text").value = "Manager";

break;

case "B":

xfa.resolveNode("form1.Page1.personalInfo.caption.value.#text").value= "Director";

break;

case "C":

xfa.resolveNode("form1.Page1.personalInfo.caption.value.#text").value= "Manager";

break;

}

11 Replies

Avatar

Former Community Member

Hi mmgiath,

form1.Page1.personalInfo.caption.value.#text will always refer to the first instance.

We need to first identify where you have added the code.

1) If the code is added on the field which is a part of the repeating instance, you can just use the script:

    

switch(xfa.event.newText)
{
case "A":
  xfa.resolveNode("this.caption.value.#text").value = "Manager";
  break;

case "B":
  xfa.resolveNode("this.caption.value.#text").value= "Director";
  break;

case "C":
  xfa.resolveNode("this.caption.value.#text").value= "Manager";
  break;
}

Avatar

Level 2

Hi mmgiath,

Try with the code of  kvdvijaykumar on event or index:change and change xfa.event.newText by this.rawValue.

Hope this helps.

Avatar

Level 7

There is a change for my original question, I apologize..:

In a repeating subform I have a text field with a caption: Manager

This which I like to achive is any time I click the button to insert a new instant

the caption to change to Director.

Is this possible?

Thanks again for your help

Avatar

Level 7

I have try this script below, without ANY LUCK!

Works for the first instant but all the next ones they have the default caption (Manager)

Any HELP?

xfa.resolveNode("form1.Page1.personalInfo.All.CostCentre_B.caption.value.#text").value = "Director”;

Avatar

Level 9

Hi   mmgiath,

I guess the problem lies in indexing of the repeated subform. If you set the index of the repeated subform right. Then it will work.

Lets say the repeating subform's name is personalInfo. You have to change the caption of CostCentre_B which is not repeating. Try the following.

var i = this.parent.index ;(choose accrodingly for your repeating subform).

var currentPersonalInfo = xfa.resolveNode(("form1.Page1.personalInfo[" + i + "]);

// some mode code as per your requirement.

currentPersonalInfo.CostCentre_B.caption.val ue.#text").value = "As sou wish”;

Hope this helps.

Thanks,

Bibhu.

Avatar

Level 7

Hi Bibhu, thank you for your reply,

Costcentre_B is a repeating field inside the repeating subform PersonalInfo.

I try your script but does not work. Any idea what I am diing wrong?

Thank you

Avatar

Level 9

Do you want to say that both subforms and fields are getting repeated?

Avatar

Level 7

Yes, both are repeating.

Thanks

Avatar

Level 5

Hi ,

The below script would help you. Keep the script on click of the button.

Subfrm1.instanceManager.addInstance(1);

var countInst = Subfrm1.instanceManager.count;

var countAct = countInst - 1;

xfa.resolveNode("Subfrm1["+countAct +"].TextField1.caption.value.#text").value = "Director"

Below link will be for your reference...

https://workspaces.acrobat.com/?d=kChABCf5oRpsk7fyR7P-vg

If you want to repeat the captions like Manager, Director, Manager, Director can be done by doing very minor modifications in the script.

Thanks

Vjay.