Ticket #6230: 6230-2.diff
File 6230-2.diff, 3.8 KB (added by , 17 years ago) |
---|
-
django/newforms/extras/widgets.py
39 39 40 40 output = [] 41 41 42 if 'id' in self.attrs: 43 id_ = self.attrs['id'] 44 else: 45 id_ = 'id_%s' % name 46 42 47 month_choices = MONTHS.items() 43 48 month_choices.sort() 44 select_html = Select(choices=month_choices).render(self.month_field % name, month_val) 49 local_attrs = self.build_attrs(id=self.month_field % id_) 50 select_html = Select(choices=month_choices).render(self.month_field % name, month_val, local_attrs) 45 51 output.append(select_html) 46 52 47 53 day_choices = [(i, i) for i in range(1, 32)] 48 select_html = Select(choices=day_choices).render(self.day_field % name, day_val) 54 local_attrs['id'] = self.day_field % id_ 55 select_html = Select(choices=day_choices).render(self.day_field % name, day_val, local_attrs) 49 56 output.append(select_html) 50 57 51 58 year_choices = [(i, i) for i in self.years] 52 select_html = Select(choices=year_choices).render(self.year_field % name, year_val) 59 local_attrs['id'] = self.year_field % id_ 60 select_html = Select(choices=year_choices).render(self.year_field % name, year_val, local_attrs) 53 61 output.append(select_html) 54 62 55 63 return mark_safe(u'\n'.join(output)) 56 64 65 def id_for_label(self, id_): 66 return '%s_month' % id_ 67 id_for_label = classmethod(id_for_label) 68 57 69 def value_from_datadict(self, data, files, name): 58 70 y, m, d = data.get(self.year_field % name), data.get(self.month_field % name), data.get(self.day_field % name) 59 71 if y and m and d: -
tests/regressiontests/forms/extra.py
22 22 >>> from django.newforms.extras import SelectDateWidget 23 23 >>> w = SelectDateWidget(years=('2007','2008','2009','2010','2011','2012','2013','2014','2015','2016')) 24 24 >>> print w.render('mydate', '') 25 <select name="mydate_month" >25 <select name="mydate_month" id="id_mydate_month"> 26 26 <option value="1">January</option> 27 27 <option value="2">February</option> 28 28 <option value="3">March</option> … … 36 36 <option value="11">November</option> 37 37 <option value="12">December</option> 38 38 </select> 39 <select name="mydate_day" >39 <select name="mydate_day" id="id_mydate_day"> 40 40 <option value="1">1</option> 41 41 <option value="2">2</option> 42 42 <option value="3">3</option> … … 69 69 <option value="30">30</option> 70 70 <option value="31">31</option> 71 71 </select> 72 <select name="mydate_year" >72 <select name="mydate_year" id="id_mydate_year"> 73 73 <option value="2007">2007</option> 74 74 <option value="2008">2008</option> 75 75 <option value="2009">2009</option> … … 84 84 >>> w.render('mydate', None) == w.render('mydate', '') 85 85 True 86 86 >>> print w.render('mydate', '2010-04-15') 87 <select name="mydate_month" >87 <select name="mydate_month" id="id_mydate_month"> 88 88 <option value="1">January</option> 89 89 <option value="2">February</option> 90 90 <option value="3">March</option> … … 98 98 <option value="11">November</option> 99 99 <option value="12">December</option> 100 100 </select> 101 <select name="mydate_day" >101 <select name="mydate_day" id="id_mydate_day"> 102 102 <option value="1">1</option> 103 103 <option value="2">2</option> 104 104 <option value="3">3</option> … … 131 131 <option value="30">30</option> 132 132 <option value="31">31</option> 133 133 </select> 134 <select name="mydate_year" >134 <select name="mydate_year" id="id_mydate_year"> 135 135 <option value="2007">2007</option> 136 136 <option value="2008">2008</option> 137 137 <option value="2009">2009</option>