1

I used the search already and found several suggestions on this topic but all of them are really old. The main hit is Dynamically adding a form to a Django formset with Ajax with more then 140 votes, but this question and also the "solution" is around 5 years old and I am wondering, if there is no build in solution in django since now.

I mean, we have all the javascript for adding a new inline form in the admin area. Is it not possible, to use the same or similar function for the front end? I don't understand, why we need a specific package, add on or what ever, since the functionality is already there...

Ok, I can not make it work, and if I am completely wrong, please explain, why I need an extra script to make this beautiful little green plus icon working in my user front end...

Any suggestions which work under Django 1.7 are very welcome!

Thanks in advance.

Community
  • 1
  • 1
drmariod
  • 11,106
  • 16
  • 64
  • 110
  • Because you need to update the -TOTAL_FORMS variable, and to do that you need js. The admin area doesn't update it automatically neither. (at least, not the default one) – dfranca Oct 20 '14 at 11:59
  • I know, I will need some js. But isn't it already there? I mean, I have to load it in my template, of course... But all these packages which provide solutions... Why isn't it possible to use the build in solution? Or am I missing something? I made a admin.StackedInline form in my admin area and I got all I need to add several objects related to the foreign key. But I can't find any solution which uses the build in JS to do the same stuff in the front end. Am I missing something? – drmariod Oct 20 '14 at 12:04
  • But the js you need is just update a variable, not big deal, (and clone de form). What bultin solution you are talking? – dfranca Oct 20 '14 at 12:24
  • This is basically the build in solution I am talking about. Isn't there a way to use this code? I was searching for some solutions and running into old code which is not working with newer Django versions, or I found this Underscore.js which is actually just another way to do it... How can I just use the already available js to add new inline forms, or isn't this the preferred way? – drmariod Oct 20 '14 at 12:35
  • 1
    Are you referring to the JavaScript that is used in Django admin for adding a row to an inline formset? It's a good starting point, but like almost all JavaScript, it supports a particular DOM. You will need to write some JavaScript that supports your DOM, especially if it's on the public side of your site. Django doesn't make any assumptions about what you need to do, nor is it a "magic" framework like Rails, which is a good thing, and by design. Dynamic formsets are a fairly easy undertaking. Give it a try and get back to us with specific questions if you have trouble. – Brandon Taylor Oct 20 '14 at 12:44

0 Answers0