Forums

Limit repeater Key values

Joao Serina 26 Jan, 2018
Hello,

I am creating a form with a repeater area with 3 fields to get information about project supervisors. I have managed to configure the repeater area to do what I want.

I want to know how can I reset or subtract values from {var:area_repeater.key}. When the first repeater is added the Key = 0 and it increments perfectly. HOWEVER, if I remove one of the repeater areas and then add another one the key value does not decrease and I will get non sequencial key values.




PS: How can I make it so that the Key value starts at 1 instead of 0?

Thank you for your time.
GreyHead 26 Jan, 2018
Hi Jaoa,

While you could do this with custom JavaScript the simplest solution is probably to use PHP in a Custom Code action in the On Submit event of the form to re-number the array elements from the repeater.

Bob
Joao Serina 26 Jan, 2018
Hello Bob,

thank you very much for the extremely fast reply! I just have two quick questions:

[list=]how do I access {var:area_repeater.key} in the code?
How do I run the function to renumber on the button press? (I can't find the function action in the button events)[/list]

Once again thanks for your time.
GreyHead 27 Jan, 2018
Hi Joao Serina ,

I have no idea how to access the repeater button press in CFv6 - I did work it out for CFv5. I do have to look at a repeater this week-end and will post if I find anything useful

Where exactly do you want to access the {var:area_repeater.key} - are you planning to write JavaScript or is this using PHP after the form submits? If it is PHP then the Debugger will give you the info you need.

Bob
Joao Serina 30 Jan, 2018
Hi Bob!
I want to do this both in JavaScript so it updates in real time (for the user) while the form is being filled but also using PHP so the form information is submitted correctly.
I will try the Debugger later. Thank you for the tip!
This topic is locked and no more replies can be posted.