Opened 18 years ago

Closed 18 years ago

#4554 closed (wontfix)

Newsforms: {{ field.error }} in HTML Template is HTML (ul) but should be Text (plain)

Reported by: djangoproject.com@… Owned by: Adrian Holovaty
Component: Forms Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Using the newforms library I do something like that in my html template:

{% for field in form %}
   {% if field.errors %}<p class="error">{{ field.errors }}</p>{% endif %}
   <label class="required">{{ field.label}}</label>{{field}}<br>
   {% if field.help_text %}<p class="help">{{ field.help_text }}</p>{% endif %}
{% endfor %}

Which renders fine as long as no field has errors. If I the user made an error and in field.errors for that reason is an error message to display {{field.errors }} renders to something like this: <ul class="errorlist"><li>This field is required.</li></ul>.
Which actually seems wrong because in this type of usage of the newforms extension I don't want <ul> and <li> html tags in my code because I do them myself (css and what not). {{ field.errors}} behaves differently from {{ field }} or {{ field.help_text }} here.
Adding a as_text ({{ field.errors.as_text}}) to does fix the problem for the moment but seems inconsistent.

Change History (1)

comment:1 by Malcolm Tredinnick, 18 years ago

Resolution: wontfix
Status: newclosed

As usual in the forms layout, a decision has been made about the default layout for an element, but you always have access to the raw information (via errors.as_text or accessing errors as a list in this case). So if you don't like the default you can change it. The current default is useful in a lot of situations and unfortunately, there isn't a one size fits all solution.

Note: See TracTickets for help on using tickets.
Back to Top