Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible error in FormSet#addAnother() #126

Open
laszbalo opened this issue Dec 20, 2015 · 0 comments
Open

Possible error in FormSet#addAnother() #126

laszbalo opened this issue Dec 20, 2015 · 0 comments

Comments

@laszbalo
Copy link

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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant