Skip to content
Advertisement

Multidimensional input : update index when clone existing item

Is it possible to change the index of the last item of a multidimensional input when my new item is created ?

Let me explain.

I have a button that is clone an item from my list, into my list. Each item contains several properties (date, category…)

This is an example of what I have when I display my form :

validation_form[classe][0][matieres][11][ressources][XXXXX][hasBeenRenewed]

What I do is that I clone all my item, but for now, the index XXXX is not updated.

How can I update the XXXX directly when I clone my item ? I thought I could count the number of items, and then change the index, but this would be painful and time consuming…

Advertisement

Answer

Use a regex in match() to create array of them then update the one you want and join() back together

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement