Reputation: 731
Is there a way to specify a django form so that a user can add more fields to it.
E.g. A user needs to list 4 names but only three fields are initially present on the page. The user would then be able to press a button and add another field for the fourth name.
I am currently doing this using javascript and httprequest.
Upvotes: 0
Views: 68
Reputation: 985
You can solve this with easy javascript as suggested.
But remember that your new fields (all fields that are not predefined in the form class) will not be used in Djangos validations.
So if you plan to put this data into your database you have to deal with the cleaning and escaping of the content you self.
Upvotes: 1
Reputation: 99650
you need something like this: django dynamic formsets
define formsets, and use jquery to show/hide them as needed
Upvotes: 1