mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Edited docs/topics/forms/index.txt changes from [9569] and fixed a typo in the visible_fields() docstring
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9592 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
		| @@ -305,15 +305,15 @@ class BaseForm(StrAndUnicode): | |||||||
|  |  | ||||||
|     def hidden_fields(self): |     def hidden_fields(self): | ||||||
|         """ |         """ | ||||||
|         Returns a list of all the BoundField objects that correspond to hidden |         Returns a list of all the BoundField objects that are hidden fields. | ||||||
|         fields in the HTML output. Useful for manual form layout in templates. |         Useful for manual form layout in templates. | ||||||
|         """ |         """ | ||||||
|         return [field for field in self if field.is_hidden] |         return [field for field in self if field.is_hidden] | ||||||
|  |  | ||||||
|     def visible_fields(self): |     def visible_fields(self): | ||||||
|         """ |         """ | ||||||
|         Returns a lits of BoundField objects that do not correspond to hidden |         Returns a list of BoundField objects that aren't hidden fields. | ||||||
|         fields. The opposite of the hidden_fields() method. |         The opposite of the hidden_fields() method. | ||||||
|         """ |         """ | ||||||
|         return [field for field in self if not field.is_hidden] |         return [field for field in self if not field.is_hidden] | ||||||
|  |  | ||||||
|   | |||||||
| @@ -304,16 +304,17 @@ templates: | |||||||
| Looping over hidden and visible fields | Looping over hidden and visible fields | ||||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||
|  |  | ||||||
| If you are manually laying out a form in a template, you will often want to | If you're manually laying out a form in a template, as opposed to relying on | ||||||
| work with any hidden fields in a single loop and then treat the visible fields | Django's default form layout, you might want to treat ``<input type="hidden">`` | ||||||
| differently. For example, since hidden fields don't display anything, putting | fields differently than non-hidden fields. For example, because hidden fields | ||||||
| their error messages "next to" the field isn't going to be very clear to the | don't display anything, putting error messages "next to" the field could cause | ||||||
| reader. So you need to handle errors for those fields a bit differently. | confusion for your users -- so errors for those fields should be handled | ||||||
|  | differently. | ||||||
|  |  | ||||||
| Django provides two methods on a form that allow you to loop over the hidden | Django provides two methods on a form that allow you to loop over the hidden | ||||||
| and visible fields independently: ``hidden_fields()`` and | and visible fields independently: ``hidden_fields()`` and | ||||||
| ``visible_fields()``. In a template, you might use these like this (this is a | ``visible_fields()``. Here's a modification of an earlier example that uses | ||||||
| modification of an earlier example):: | these two methods:: | ||||||
|  |  | ||||||
|     <form action="/contact/" method="POST"> |     <form action="/contact/" method="POST"> | ||||||
|         {% for field in form.visible_fields %} |         {% for field in form.visible_fields %} | ||||||
| @@ -336,7 +337,7 @@ modification of an earlier example):: | |||||||
| This example does not handle any errors in the hidden fields. Usually, an | This example does not handle any errors in the hidden fields. Usually, an | ||||||
| error in a hidden field is a sign of form tampering, since normal form | error in a hidden field is a sign of form tampering, since normal form | ||||||
| interaction won't alter them. However, you could easily insert some error | interaction won't alter them. However, you could easily insert some error | ||||||
| displays for those form errors as well. | displays for those form errors, as well. | ||||||
|  |  | ||||||
| .. versionadded:: 1.1 | .. versionadded:: 1.1 | ||||||
|     The ``hidden_fields`` and ``visible_fields`` methods are new in Django |     The ``hidden_fields`` and ``visible_fields`` methods are new in Django | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user