diff --git a/django/newforms/forms.py b/django/newforms/forms.py
index 2c481e4..fac6915 100644
a
|
b
|
class BoundField(StrAndUnicode):
|
272 | 272 | return self.form.errors.get(self.name, self.form.error_class()) |
273 | 273 | errors = property(_errors) |
274 | 274 | |
275 | | def as_widget(self, widget=None, attrs=None): |
276 | | """ |
277 | | Renders the field by rendering the passed widget, adding any HTML |
278 | | attributes passed as attrs. If no widget is specified, then the |
279 | | field's default widget will be used. |
280 | | """ |
| 275 | def get_data_attrs_and_widget(self, widget, attrs): |
281 | 276 | if not widget: |
282 | 277 | widget = self.field.widget |
283 | 278 | attrs = attrs or {} |
… |
… |
class BoundField(StrAndUnicode):
|
290 | 285 | data = data() |
291 | 286 | else: |
292 | 287 | data = self.data |
| 288 | return data, attrs, widget |
| 289 | |
| 290 | def as_widget(self, widget=None, attrs=None): |
| 291 | """ |
| 292 | Renders the field by rendering the passed widget, adding any HTML |
| 293 | attributes passed as attrs. If no widget is specified, then the |
| 294 | field's default widget will be used. |
| 295 | """ |
| 296 | data, attrs, widget = self.get_data_attrs_and_widget(widget, attrs) |
293 | 297 | return widget.render(self.html_name, data, attrs=attrs) |
294 | 298 | |
295 | 299 | def as_text(self, attrs=None): |
… |
… |
class BoundField(StrAndUnicode):
|
348 | 352 | return self.html_name |
349 | 353 | return '' |
350 | 354 | auto_id = property(_auto_id) |
| 355 | |
| 356 | def __iter__(self): |
| 357 | data, attrs, _ = self.get_data_attrs_and_widget(None, None) #widget, attrs) |
| 358 | for i in self.field.widget.iter(self.html_name, data, attrs=attrs): |
| 359 | yield i |
| 360 | |
| 361 | def __getitem__(self, i): |
| 362 | items_list = [] |
| 363 | items_dict = {} |
| 364 | for item in self: |
| 365 | items_list.append(item) |
| 366 | items_dict[item.choice_value] = item |
| 367 | try: |
| 368 | return items_list[i] |
| 369 | except TypeError: |
| 370 | return items_dict[i] |
diff --git a/django/newforms/widgets.py b/django/newforms/widgets.py
index 20a7cab..3dc89e1 100644
a
|
b
|
class RadioSelect(Select):
|
341 | 341 | def render(self, name, value, attrs=None, choices=()): |
342 | 342 | return self.get_renderer(name, value, attrs, choices).render() |
343 | 343 | |
| 344 | def iter(self, name, value, attrs=None, choices=()): |
| 345 | for i in self.get_renderer(name, value, attrs, choices): |
| 346 | yield i |
| 347 | |
344 | 348 | def id_for_label(self, id_): |
345 | 349 | # RadioSelect is represented by multiple <input type="radio"> fields, |
346 | 350 | # each of which has a distinct ID. The IDs are made distinct by a "_X" |
diff --git a/tests/regressiontests/forms/widgets.py b/tests/regressiontests/forms/widgets.py
index 0e69602..d75a468 100644
a
|
b
|
u'<ul>\n<li><label><input checked="checked" type="radio" name="email" value="\u0
|
757 | 757 | <li><label><input type="radio" id="bar_3" value="R" name="beatle" /> Ringo</label></li> |
758 | 758 | </ul> |
759 | 759 | |
| 760 | >>> w = RadioSelect() |
| 761 | >>> for i in w.iter('beatle', 'J', choices=(('J', 'John'), ('P', 'Paul'), ('G', 'George'), ('R', 'Ringo')), attrs={'id':'bar'}): |
| 762 | ... print i |
| 763 | <label><input checked="checked" type="radio" id="bar_0" value="J" name="beatle" /> John</label> |
| 764 | <label><input type="radio" id="bar_1" value="P" name="beatle" /> Paul</label> |
| 765 | <label><input type="radio" id="bar_2" value="G" name="beatle" /> George</label> |
| 766 | <label><input type="radio" id="bar_3" value="R" name="beatle" /> Ringo</label> |
| 767 | |
760 | 768 | # CheckboxSelectMultiple Widget ############################################### |
761 | 769 | |
762 | 770 | >>> w = CheckboxSelectMultiple() |