Code

Opened 7 years ago

Closed 7 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
Component: Forms Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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.

Attachments (0)

Change History (1)

comment:1 Changed 7 years ago by mtredinnick

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

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.

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.