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

Numbering Instances of a Subform

Avatar

Level 1

          I have a maintenance form where each item that gets inspected needs to have a unique number. The Item # is a Numeric Field and I have tried many different ways to count the Subform1 instances but nothing works 100% of the time.  The issue is I can count the instances on initialize or I can add 1 to the index but it doesn't work if I need to remove sections. I need to find a way that correctly identifies the item number despite errors made by the user when they need to remove sections. I've also tried just have the item # be the page number but some inspections last more than one page so this is not a solution either.


Thanks for you help - I'm sure the answer is fairly simple (the form is built in javascript)

1 Accepted Solution

Avatar

Correct answer by
Level 10

This makes no big difference.

Nmb.rawValue = this.index + 1;

View solution in original post

4 Replies

Avatar

Level 10

Hi,

assumed you have a repeatable subform "SF" which contains a numeric field "Nmb".

You can update the instance count with a small script (FormCalc) in the indexChange event of your subform.

form1.#subform[0].SF::indexChange - (FormCalc, client)

Nmb = $.index + 1

Avatar

Level 1

I think this issue there is that I'm using javascript not formcalc.

Avatar

Correct answer by
Level 10

This makes no big difference.

Nmb.rawValue = this.index + 1;

Avatar

Level 1

It worked....I had to add a couple of parents in so it was this.parent.parent.index +1 just for other people wondering why it might not work. I put the script in the layout:ready event location.