From c4070e86c8067cbd615b6f1eb4f30098bd684da5 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Wed, 15 Nov 2006 23:09:10 +0000 Subject: [PATCH] Fixed #3025 -- Added auto_id option to Form.__init__(). Thanks, SmileyChris git-svn-id: http://code.djangoproject.com/svn/django/trunk@4073 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/newforms/forms.py | 20 +++++++++- tests/regressiontests/forms/tests.py | 55 ++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/django/newforms/forms.py b/django/newforms/forms.py index e490d0d5f9..6859ba2a37 100644 --- a/django/newforms/forms.py +++ b/django/newforms/forms.py @@ -23,8 +23,9 @@ class Form(object): "A collection of Fields, plus their associated data." __metaclass__ = DeclarativeFieldsMetaclass - def __init__(self, data=None): # TODO: prefix stuff + def __init__(self, data=None, auto_id=False): # TODO: prefix stuff self.data = data or {} + self.auto_id = auto_id self.clean_data = None # Stores the data after clean() has been called. self.__errors = None # Stores the errors after clean() has been called. @@ -156,6 +157,10 @@ class BoundField(object): errors = property(_errors) def as_widget(self, widget, attrs=None): + attrs = attrs or {} + auto_id = self.auto_id + if not attrs.has_key('id') and not widget.attrs.has_key('id') and auto_id: + attrs['id'] = auto_id return widget.render(self._name, self._form.data.get(self._name, None), attrs=attrs) def as_text(self, attrs=None): @@ -167,3 +172,16 @@ class BoundField(object): def as_textarea(self, attrs=None): "Returns a string of HTML for representing this as a