fix: never reuse a collection entry index after a removal

This commit is contained in:
fromme committed 2026-09-30 18:05:23 +02:00
1 parent ede8fd840a
commit 972839286c
1 file changed
+4 -1
@@ -11,10 +11,13 @@ export default class extends Controller {
connect() {
this.itemsCountValue = this.fieldTargets.length
// A running counter rather than the current count: after a remove, count + 1 can be an
// index a remaining entry still holds, and the two would submit into the same slot.
this.nextIndex = this.fieldTargets.length
}
addItem() {
const index = this.fieldTargets.length + 1
const index = this.nextIndex++
const prototype = JSON.parse(this.prototypeValue)
const newField = prototype.replace(/__name__/g, index)
this.fieldsTarget.insertAdjacentHTML('beforeend', newField)