diff --git a/AUTHORS b/AUTHORS index 7ea97b5537f08..7bb1408d5f1aa 100644 --- a/AUTHORS +++ b/AUTHORS @@ -171,6 +171,7 @@ answer newbie questions, and generally made Django that much better: Alex Gaynor Andy Gayton Idan Gazit + geber@datacollect.com Baishampayan Ghose Dimitris Glezos glin@seznam.cz @@ -265,6 +266,7 @@ answer newbie questions, and generally made Django that much better: Finn Gruwier Larsen Lau Bech Lauritzen Rune Rønde Laursen + Mark Lavin Eugene Lazutkin lcordier@point45.com Jeong-Min Lee diff --git a/django/forms/forms.py b/django/forms/forms.py index 0b7c2e233834d..705058a6e6c8e 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -343,6 +343,7 @@ def __init__(self, form, field, name): self.name = name self.html_name = form.add_prefix(name) self.html_initial_name = form.add_initial_prefix(name) + self.html_initial_id = form.add_initial_prefix(self.auto_id) if self.field.label is None: self.label = pretty_name(name) else: @@ -374,7 +375,10 @@ def as_widget(self, widget=None, attrs=None, only_initial=False): attrs = attrs or {} auto_id = self.auto_id if auto_id and 'id' not in attrs and 'id' not in widget.attrs: - attrs['id'] = auto_id + if not only_initial: + attrs['id'] = auto_id + else: + attrs['id'] = self.html_initial_id if not self.form.is_bound: data = self.form.initial.get(self.name, self.field.initial) if callable(data): diff --git a/tests/regressiontests/forms/forms.py b/tests/regressiontests/forms/forms.py index bf9623fe7713f..b204580131fc6 100644 --- a/tests/regressiontests/forms/forms.py +++ b/tests/regressiontests/forms/forms.py @@ -1807,4 +1807,11 @@ >>> [f.name for f in form.visible_fields()] ['artist', 'name'] +# Hidden initial input gets its own unique id ################################ + +>>> class MyForm(Form): +... field1 = CharField(max_length=50, show_hidden_initial=True) +>>> print MyForm() + + """