diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-12-05 04:22:00 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-12-05 04:22:00 +0000 |
| commit | bfab9d62ee815baac34b1872676ad26af91c7d94 (patch) | |
| tree | 60a3f28b63726b4fa4c2a201e6d930983741b384 /django/forms | |
| parent | dfef20a7806073dab547eeb1c5e700c4bd0e1634 (diff) | |
Added a way to iterate over hidden/visible fields in a form. Useful for manual
form layout.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9569 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/forms')
| -rw-r--r-- | django/forms/forms.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/django/forms/forms.py b/django/forms/forms.py index e28479fb8b..29c4f31115 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -303,6 +303,20 @@ class BaseForm(StrAndUnicode): return True return False + def hidden_fields(self): + """ + Returns a list of all the BoundField objects that correspond to hidden + fields in the HTML output. Useful for manual form layout in templates. + """ + return [field for field in self if field.is_hidden] + + def visible_fields(self): + """ + Returns a lits of BoundField objects that do not correspond to hidden + fields. The opposite of the hidden_fields() method. + """ + return [field for field in self if not field.is_hidden] + class Form(BaseForm): "A collection of Fields, plus their associated data." # This is a separate class from BaseForm in order to abstract the way @@ -363,7 +377,7 @@ class BoundField(StrAndUnicode): else: name = self.html_initial_name return widget.render(name, data, attrs=attrs) - + def as_text(self, attrs=None, **kwargs): """ Returns a string of HTML for representing this as an <input type="text">. |
