insin / insin/newforms

Possible error in FormSet#addAnother()

Open
#126 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
634
Forks
46
PR merge metrics
No merged PRs in 30d

Description

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,

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.