Ticket #6230: 6230-2.diff

File 6230-2.diff, 3.8 KB (added by Matt McClanahan, 17 years ago)
  • django/newforms/extras/widgets.py

     
    3939
    4040        output = []
    4141
     42        if 'id' in self.attrs:
     43            id_ = self.attrs['id']
     44        else:
     45            id_ = 'id_%s' % name
     46
    4247        month_choices = MONTHS.items()
    4348        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)
    4551        output.append(select_html)
    4652
    4753        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)
    4956        output.append(select_html)
    5057
    5158        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)
    5361        output.append(select_html)
    5462
    5563        return mark_safe(u'\n'.join(output))
    5664
     65    def id_for_label(self, id_):
     66        return '%s_month' % id_
     67    id_for_label = classmethod(id_for_label)
     68
    5769    def value_from_datadict(self, data, files, name):
    5870        y, m, d = data.get(self.year_field % name), data.get(self.month_field % name), data.get(self.day_field % name)
    5971        if y and m and d:
  • tests/regressiontests/forms/extra.py

     
    2222>>> from django.newforms.extras import SelectDateWidget
    2323>>> w = SelectDateWidget(years=('2007','2008','2009','2010','2011','2012','2013','2014','2015','2016'))
    2424>>> print w.render('mydate', '')
    25 <select name="mydate_month">
     25<select name="mydate_month" id="id_mydate_month">
    2626<option value="1">January</option>
    2727<option value="2">February</option>
    2828<option value="3">March</option>
     
    3636<option value="11">November</option>
    3737<option value="12">December</option>
    3838</select>
    39 <select name="mydate_day">
     39<select name="mydate_day" id="id_mydate_day">
    4040<option value="1">1</option>
    4141<option value="2">2</option>
    4242<option value="3">3</option>
     
    6969<option value="30">30</option>
    7070<option value="31">31</option>
    7171</select>
    72 <select name="mydate_year">
     72<select name="mydate_year" id="id_mydate_year">
    7373<option value="2007">2007</option>
    7474<option value="2008">2008</option>
    7575<option value="2009">2009</option>
     
    8484>>> w.render('mydate', None) == w.render('mydate', '')
    8585True
    8686>>> print w.render('mydate', '2010-04-15')
    87 <select name="mydate_month">
     87<select name="mydate_month" id="id_mydate_month">
    8888<option value="1">January</option>
    8989<option value="2">February</option>
    9090<option value="3">March</option>
     
    9898<option value="11">November</option>
    9999<option value="12">December</option>
    100100</select>
    101 <select name="mydate_day">
     101<select name="mydate_day" id="id_mydate_day">
    102102<option value="1">1</option>
    103103<option value="2">2</option>
    104104<option value="3">3</option>
     
    131131<option value="30">30</option>
    132132<option value="31">31</option>
    133133</select>
    134 <select name="mydate_year">
     134<select name="mydate_year" id="id_mydate_year">
    135135<option value="2007">2007</option>
    136136<option value="2008">2008</option>
    137137<option value="2009">2009</option>
Back to Top