﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
9125	as_p() produces wrong output sometimes	Ivan Giuliani	Ivan Giuliani	"While investigating on #8720 I ran into the following issue. Consider the following view:

{{{
#!python
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."		closed	Forms	1.0		fixed	as_p, form, forms		Unreviewed	0	0	0	0	0	0
