Reputation: 45932
I have a simple Django form:
class CommentForm(forms.Form):
comment = forms.CharField(max_length=2000, required=True)
post_id = forms.CharField(max_length=2000, widget=forms.HiddenInput, required=True)
parent_id = forms.CharField(max_length=2000, widget=forms.HiddenInput, required=True)
Now I want to print this form several times on my page - I am doing it through a template tag, so the new form is created each time. The problem is, that I get the same ID's for all fields.
I know about the prefix, but I do not want to change field names, because there is one handler for all forms, only to set unique IDs.
So my question:
Upvotes: 10
Views: 10702
Reputation: 196
You can control how the automatic IDs are generated with the auto_id parameter when you create a new instance of that form
Have a look here (search for auto_id):
http://docs.djangoproject.com/en/dev/ref/forms/api/#configuring-html-label-tags
Upvotes: 18