﻿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
6138	newforms: when accessing directly form.errors, error_class is not used	Michal Moroz	Peter Mott	"Tested with SVN Django, rev 6897.

Short guide for reproducing the problem:
 * write custom form class and ErrorList-based class
 * make instance of the form which defined error_class as our ErrorList-based class and some non-valid data
 * watch customform.errors and customform!['customfield'].errors, they are instances of ErrorList, not our error_class

The long guide (small app for reproducing the problem):[[BR]]
urls.py (within project dtest)
{{{
from django.conf.urls.defaults import *

urlpatterns = patterns('',
    url(r'^form/$', 'dtest.newforms.views.microform', {'form':'form.html'}),
    url(r'^form2/$', 'dtest.newforms.views.microform', {'form':'form2.html'}),
)
}}}

newforms/forms.py
{{{
from django.utils.encoding import force_unicode
from django import newforms as forms

attrs_dict = { 'class': 'required' }

class ErrList(forms.util.ErrorList):
    def __unicode__(self):
        return 'errors: %s' % ''.join([unicode(e) for e in self])

class MicroForm(forms.Form):
    username = forms.CharField(max_length=30,
                               widget=forms.TextInput(attrs=attrs_dict),
                               label=u'username')
    def clean(self):
        if self.cleaned_data.get('username', '') is not 'blah':
            raise forms.ValidationError('we have a problem here')
}}}
newforms/views.py
{{{
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext

from dtest.newforms.forms import ErrList, MicroForm

def microform(request, form='form.html'):
    if request.method == 'POST':
        m = MicroForm(request.POST, error_class=ErrList)
        if m.is_valid():
            return HttpResponse('OK')
    else:
        m = MicroForm()

    return render_to_response(form,
        { 'form': m },
        context_instance=RequestContext(request))
}}}
templates/form.html
{{{
<form action="""" method=""POST"">
<dl>
{% for field in form %}
    <dt>{{ field.label_tag }}</dt>
    <dd {% if field.errors %}class=""errorfield"" {% endif %}>{{ field }}</dd>
    {% if field.help_text %}<dd>{{ field.help_text }}</dd>{% endif %}
    {% if field.errors %}<dd class=""errors"">{{ field.errors }}</dd>{% endif %}
{% endfor %}
</dl>
<div class=""submit""><input id=""submit"" type=""submit"" value=""Sign up"" />
</form>
}}}
templates/form2.html
{{{
<form action="""" method=""POST"">
<ul>
{{ form.as_ul }}
</ul>
<div class=""submit""><input id=""submit"" type=""submit"" value=""Sign up"" />
}}}

 * When accessing form/, the ErrList does not work.
 * When accessing form2/, the to_ul() (and _html_output() too) method works with ErrList, but non_field_errors() do not.

A simple patch is included below. It fixes the problem, but I do not guarantee working with the rest of the code in all cases."		closed	Forms	dev		fixed		michalmoroz@… Jesse Young gz Peter Mott	Accepted	1	0	0	0	0	0
