Opened 16 years ago
Closed 16 years ago
#9125 closed (fixed)
as_p() produces wrong output sometimes
Reported by: | Ivan Giuliani | Owned by: | Ivan Giuliani |
---|---|---|---|
Component: | Forms | Version: | 1.0 |
Severity: | Keywords: | as_p, form, forms | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
While investigating on #8720 I ran into the following issue. Consider the following view:
from django.template import Context, Template from django.http import HttpResponse from django import forms class TestForm(forms.Form): initial_data = [1,2,3,4] testfield = forms.MultipleChoiceField(initial=initial_data, required=False, widget=forms.MultipleHiddenInput()) def tform(request): if request.method == 'POST': form = TestForm(request.POST) else: form = TestForm() t = Template('<html><body><form action="." method="POST">{{ form.as_p }}<input type="submit" /></form></body></html>') c = Context({ 'form' : form }) return HttpResponse(t.render(c))
If you submit the form you'll get the following output:
<html><body> <form action="." method="POST"> <ul class="errorlist"> <li>(Hidden field testfield) Select a valid choice. 1 is not one of the available choices.</li> <<input type="hidden" name="testfield" value="1" id="id_testfield" /> <input type="hidden" name="testfield" value="2" id="id_testfield" /> <input type="hidden" name="testfield" value="3" id="id_testfield" /> <input type="hidden" name="testfield" value="4" id="id_testfield" /></p> <input type="submit" /></form></body></html>
Notice the missing <p>
tag after the error line.
I tried with as_table
and as_ul
as well, and they render the form correctly.
Note:
See TracTickets
for help on using tickets.
Fixed in [9067]