Handling dynamic input groups
<p>I am creating a form where a part of it would be cloned using javascript. The input name is of type <code>input[ID][date]</code>, <code>input[ID][type]</code> etc. where the ID is the group of inputs. Those will be relationship IDs decided after the form submission.</p>
<p>I am currently having a placeholder for ID which gets replaced on cloning by the current element count.</p>
<h3>Problem</h3>
<p>When someone adds 3 elements ([0],[1],[2]) and removes the first one, the next ID of the element will be 2, same as the third element, overtwriting its inputs. I can't use <code>input[][date]</code> because it will create separate array for each input.</p>
<h3>Question</h3>
<p>What is the best way to approach dynamic input arrays? Should I keep the ID as a variable and increment it every time so it's unique even after removing an element? Would random temporary ID work? (I guess it could repeat that way)</p>