diff --git a/django/forms/forms.py b/django/forms/forms.py
a
|
b
|
|
502 | 502 | return self.field.widget.is_hidden |
503 | 503 | is_hidden = property(_is_hidden) |
504 | 504 | |
| 505 | def _required(self): |
| 506 | "Returns True if this BoundField's field is required." |
| 507 | return self.field.required |
| 508 | required = property(_required) |
| 509 | |
505 | 510 | def _auto_id(self): |
506 | 511 | """ |
507 | 512 | Calculates and returns the ID attribute for this BoundField, if the |
diff --git a/tests/regressiontests/forms/forms.py b/tests/regressiontests/forms/forms.py
a
|
b
|
|
1739 | 1739 | <input type="submit" /> |
1740 | 1740 | </form> |
1741 | 1741 | |
| 1742 | Use form.[field].required to identify required fields. |
| 1743 | >>> class OptionalPersonForm(Form): |
| 1744 | ... first_name = CharField() |
| 1745 | ... last_name = CharField() |
| 1746 | ... nick_name = CharField(required=False) |
| 1747 | >>> t = Template('<p class="{% if field.required %}required{% else %}optional{% endif %}"><label>{{ field.label }}: {{ field }}</label></p>') |
| 1748 | >>> for boundfield in OptionalPersonForm(auto_id=False): |
| 1749 | ... print t.render(Context({'field': boundfield})) |
| 1750 | <p class="required"><label>First name: <input type="text" name="first_name" /></label></p> |
| 1751 | <p class="required"><label>Last name: <input type="text" name="last_name" /></label></p> |
| 1752 | <p class="optional"><label>Nick name: <input type="text" name="nick_name" /></label></p> |
1742 | 1753 | |
1743 | 1754 | # The empty_permitted attribute ############################################## |
1744 | 1755 | |