Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #6230: Fixed the addition of id values to the select widgets in

SelectDateWidget. Thanks, Matt McClanahan.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@7291 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ec0bbc15a82cb1cf394a1296024b8e0b35d70728 1 parent 4b9497c
@malcolmt malcolmt authored
View
18 django/newforms/extras/widgets.py
@@ -39,21 +39,33 @@ def render(self, name, value, attrs=None):
output = []
+ if 'id' in self.attrs:
+ id_ = self.attrs['id']
+ else:
+ id_ = 'id_%s' % name
+
month_choices = MONTHS.items()
month_choices.sort()
- select_html = Select(choices=month_choices).render(self.month_field % name, month_val)
+ local_attrs = self.build_attrs(id=self.month_field % id_)
+ select_html = Select(choices=month_choices).render(self.month_field % name, month_val, local_attrs)
output.append(select_html)
day_choices = [(i, i) for i in range(1, 32)]
- select_html = Select(choices=day_choices).render(self.day_field % name, day_val)
+ local_attrs['id'] = self.day_field % id_
+ select_html = Select(choices=day_choices).render(self.day_field % name, day_val, local_attrs)
output.append(select_html)
year_choices = [(i, i) for i in self.years]
- select_html = Select(choices=year_choices).render(self.year_field % name, year_val)
+ local_attrs['id'] = self.year_field % id_
+ select_html = Select(choices=year_choices).render(self.year_field % name, year_val, local_attrs)
output.append(select_html)
return mark_safe(u'\n'.join(output))
+ def id_for_label(self, id_):
+ return '%s_month' % id_
+ id_for_label = classmethod(id_for_label)
+
def value_from_datadict(self, data, files, name):
y, m, d = data.get(self.year_field % name), data.get(self.month_field % name), data.get(self.day_field % name)
if y and m and d:
View
12 tests/regressiontests/forms/extra.py
@@ -22,7 +22,7 @@
>>> from django.newforms.extras import SelectDateWidget
>>> w = SelectDateWidget(years=('2007','2008','2009','2010','2011','2012','2013','2014','2015','2016'))
>>> print w.render('mydate', '')
-<select name="mydate_month">
+<select name="mydate_month" id="id_mydate_month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
@@ -36,7 +36,7 @@
<option value="11">November</option>
<option value="12">December</option>
</select>
-<select name="mydate_day">
+<select name="mydate_day" id="id_mydate_day">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
@@ -69,7 +69,7 @@
<option value="30">30</option>
<option value="31">31</option>
</select>
-<select name="mydate_year">
+<select name="mydate_year" id="id_mydate_year">
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
@@ -84,7 +84,7 @@
>>> w.render('mydate', None) == w.render('mydate', '')
True
>>> print w.render('mydate', '2010-04-15')
-<select name="mydate_month">
+<select name="mydate_month" id="id_mydate_month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
@@ -98,7 +98,7 @@
<option value="11">November</option>
<option value="12">December</option>
</select>
-<select name="mydate_day">
+<select name="mydate_day" id="id_mydate_day">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
@@ -131,7 +131,7 @@
<option value="30">30</option>
<option value="31">31</option>
</select>
-<select name="mydate_year">
+<select name="mydate_year" id="id_mydate_year">
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
Please sign in to comment.
Something went wrong with that request. Please try again.