Skip to content

Formsets by Ref #139

@bkotch

Description

@bkotch

In your documentation, you show managing the formsets by storing the constructed form in the state.

http://newforms.readthedocs.io/en/latest/formsets.html?highlight=formset

var ArticleFormSet = forms.FormSet.extend({form: Article})
var BookFormSet = forms.FormSet.extend({form: Book})

var PublicationManager = React.createClass({
  getInitialState: function() {
    return {
      articleFormset: new ArticleFormSet({prefix: 'articles'})
    , bookFormset: new BookFormSet({prefix: 'books'})
    }
  },

  // ...rendering implemented as normal...

  onSubmit: function(e) {
    e.preventDefault()
    var articlesValid = this.state.articleFormset.validate()
    var booksValid = this.state.bookFormset.validate()
    if (articlesValid && booksValid) {
      // Do something with cleanedData() on the formsets
    }
  }
})

Is there a way we can do it via ref so we can reference the formset later and just allow the formset to render when the props update?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions