0

I have a complex form containing an inline formset, which basically has got some text fields and a file upload field. Now, I want to enable the user to create a new record, and within the same step attach several files.

I think there are different options to achieve this, maybe I could write a jQuery-Plugin that clones the formset, do all the validation and inserting stuff manually in the view etc.

The main point before I begin is: I wonder if there isn't any solution out there that takes cares of the problem - in my opinion, this is a very common problem.

Maybe there is some approach of a solution I did not notice?

schneck
  • 10,556
  • 11
  • 49
  • 74
  • See this question and answer: http://stackoverflow.com/questions/501719/dynamically-adding-a-form-to-a-django-formset-with-ajax – Van Gale Sep 30 '09 at 04:56
  • Also, to answer your concern about server side functionality, the question/answer linked above uses the stock Django formset methods, which may not be glamorous but they get the job done. – Van Gale Sep 30 '09 at 04:59
  • Thanks for your answer, I already have a self-written jQuery-Plugin that clones dom-nodes and updates ids within it. My concern is in fact more about the server-side fieldset handling: For example, if the users submits an invalid form, all that files uploaded in the fieldset have to be saved temporarily, and pushed back to the form. Of course, I can do this manually in my view, but I ask myself if it's not possible to make some kind of generic function of it, so that I can reuse it, and I'm looking for the best way to begin. – schneck Sep 30 '09 at 08:07

1 Answers1

0

If you basically just want an "Add another" or + link that adds a new section to your form a nice approach is to write a dumb section in plain HTML then hide it with css and use cloneNode(true) to make a copy. As long as you don't use ids you should be able to cleanly generate many copies with very little JS code.

Tom
  • 162
  • 2
  • 11
  • Yes, this would be possible, but this is only the client side. Will I have to implement all the server side stuff on my own or ist there any existing functionality I could use? – schneck Sep 29 '09 at 21:52