Django

Code

Ticket #9125 (closed: fixed)

Opened 3 months ago

Last modified 3 months ago

as_p() produces wrong output sometimes

Reported by: kratorius Assigned to: kratorius
Milestone: Component: Forms
Version: 1.0 Keywords: as_p, form, forms
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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.

Attachments

Change History

09/18/08 02:17:27 changed by mtredinnick

  • status changed from new to closed.
  • needs_better_patch changed.
  • resolution set to fixed.
  • needs_tests changed.
  • needs_docs changed.

Fixed in [9067]


Add/Change #9125 (as_p() produces wrong output sometimes)




Change Properties
Action