diff --git a/django/newforms/forms.py b/django/newforms/forms.py index e490d0d5f9d..6859ba2a379 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