Django Dynamic Formset, v1.2

So, it’s two months later than I’d estimated, but sometime this morning, I committed version 1.2. In spite of the delay (which is a story for another time), I’m pretty excited about this release — I got to add a couple of nifty features, and squash some bugs in the process (thanks for the bug reports and patches, guys).

Here’s the list of changes:

  • Inline formsets created with “can_delete” set to True are now supported properly; clicking the “remove” link hides the form and sets the DELETE field, so Django handles the deleting when the page is POSTed.
  • Added form templates: you can now specify a form that will be cloned to generate the forms in the formset. As a side-effect, you can now delete all forms in a formset, and the “add” link still works as expected.
  • Clicking the “add” link now clones the last form, instead of the first; this works much better in the admin, especially if you have one or more extra forms (thanks justhamade).
  • Added an optional setting “extraClasses”; set this is an array of CSS classes, and they’ll be applied to the formset’s rows in turn. So, to get the row-striping effect in the Django admin, you’d do something like this:
    $('...').formset({extraClasses: ['row1', 'row2']});

    Adding and removing forms keeps the classes in sync, so your stripes don’t get all mix’d up — hopefully, this is a feature, but time will tell.

  • Updated examples and documentation.

As always, you can download the latest release from the Google Code page, or use the links below: