Reputation: 6239
My form is
class AnswerForm(ModelForm):
class Meta:
model=Answers
fields=['answer']
widgets ={'answer': TinyMCE(attrs={'cols': 80, 'rows': 30}, mce_attrs={'mode':"textareas",}),}
and in my view I am creating an instance of the form answerForm=AnswerForm()
. In the template I have many instances of the answerForm inside a for loop
<form action="/q/answer/" method="post" style="display:none;" class="answer_form" >
{% csrf_token %}
{# {{ context.answerForm.as_p }} #}
{# <textarea id="{{ forloop.counter }}">{{ context.answerForm.answer }}</textarea> #}
{{ context.answerForm.answer }}
<input type="hidden" name="q_id_a" id="q_id_a" value="{{ result.object.id }}">
<input type="submit" value="Submit" />
my question:
ContactForm(auto_id='id_for_%s')
as mentioned in the django form documents modifies the id name format for all the form fields, but still I could not understand how to make django form field unique for multiple instances.Upvotes: 2
Views: 926
Reputation: 599628
If you have multiple instances of a form on a page, you should be using a formset, which will take care of creating unique IDs and field names for you.
Upvotes: 4