diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2006-12-07 06:17:06 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2006-12-07 06:17:06 +0000 |
| commit | 44add112e554d9eb5a66ad4b118501a0cac9ffc1 (patch) | |
| tree | 8bacfa3c7e667ccb35850e4505f6f00a3cf5f49b /django/newforms/forms.py | |
| parent | 3d1ceab1aa894d522af614b1a2f6f77e4b4571a6 (diff) | |
newforms: Form.as_ul() no longer puts hidden fields between <li>s. Similar to [4175], which was the same thing for Form.as_table(). Refs #3101
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4177 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/newforms/forms.py')
| -rw-r--r-- | django/newforms/forms.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/django/newforms/forms.py b/django/newforms/forms.py index 9e4fc30a7a..36dd36fcce 100644 --- a/django/newforms/forms.py +++ b/django/newforms/forms.py @@ -102,18 +102,26 @@ class Form(StrAndUnicode): def as_ul(self): "Returns this form rendered as HTML <li>s -- excluding the <ul></ul>." top_errors = self.non_field_errors() - output = [] + output, hidden_fields = [], [] for name, field in self.fields.items(): bf = BoundField(self, field, name) if bf.is_hidden: new_errors = bf.errors # Cache in local variable. if new_errors: top_errors.extend(['(Hidden field %s) %s' % (name, e) for e in new_errors]) - output.append(unicode(bf)) + hidden_fields.append(unicode(bf)) else: output.append(u'<li>%s%s %s</li>' % (bf.errors, bf.label_tag(escape(bf.verbose_name+':')), bf)) if top_errors: output.insert(0, u'<li>%s</li>' % top_errors) + if hidden_fields: # Insert any hidden fields in the last <li>. + str_hidden = u''.join(hidden_fields) + if output: + last_li = output[-1] + # Chop off the trailing '</li>' and insert the hidden fields. + output[-1] = last_li[:-5] + str_hidden + '</li>' + else: # If there aren't any '<li>'s in the output, just append the hidden fields. + output.append(str_hidden) return u'\n'.join(output) def non_field_errors(self): |
