Code

Opened 6 years ago

Closed 6 years ago

#9125 closed (fixed)

as_p() produces wrong output sometimes

Reported by: kratorius Owned by: kratorius
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: UI/UX:

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 (0)

Change History (1)

comment:1 Changed 6 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to fixed
  • Status changed from new to closed

Fixed in [9067]

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.