newforms icon indicating copy to clipboard operation
newforms copied to clipboard

Possible error in FormSet#addAnother()

Open laszbalo opened this issue 10 years ago • 0 comments

How to reproduce?

  1. Creating a FormSet object
  2. FormSet#addAnother() => name="form-0-...."
  3. FormSet#addAnother() => name="form-0-...." name="form-1-...."
  4. FormSet#removeForm(0) => basically any index other than the highest name="form-1-....
  5. FormSet#addAnother() => the sequence number of the newly created field is always equal to FormSet#totalFormCount() name="form-1-...." name="form-1-...."

As a result, the new field either contains the value of the "form-FormSet#totalFormCount()-....", if it was filled in, or behaves weirdly when I start typing.

Please, correct me, if I am wrong, but I believe, that the FormSet#_constructForm() should be called with a unique sequence number, rather then FormSet#totalFormCount(). https://github.com/insin/newforms/blob/react/src/FormSet.js#L596

At the moment I am passing _constructForm a counter, which increases by one every time when addAnother is called.

So by calling FormSet#addAnother() in step 5, I would get => name="form-1-...." name="form-2-...."

All the current test were passed, so I suppose, it should not break anything. It is a minor change, but if you are happy with this solution, I could send a PR. With thanks,

laszbalo avatar Dec 20 '15 22:12 laszbalo