Ticket #6458: make_radioselect_iterable.diff
File make_radioselect_iterable.diff, 3.3 KB (added by , 17 years ago) |
---|
-
django/newforms/forms.py
255 255 return self.form.errors.get(self.name, self.form.error_class()) 256 256 errors = property(_errors) 257 257 258 def as_widget(self, widget=None, attrs=None): 259 """ 260 Renders the field by rendering the passed widget, adding any HTML 261 attributes passed as attrs. If no widget is specified, then the 262 field's default widget will be used. 263 """ 264 if not widget: 265 widget = self.field.widget 258 def get_data_and_attrs(self, widget, attrs): 266 259 attrs = attrs or {} 267 260 auto_id = self.auto_id 268 261 if auto_id and 'id' not in attrs and 'id' not in widget.attrs: … … 273 266 data = data() 274 267 else: 275 268 data = self.data 269 return data, attrs 270 271 def as_widget(self, widget=None, attrs=None): 272 """ 273 Renders the field by rendering the passed widget, adding any HTML 274 attributes passed as attrs. If no widget is specified, then the 275 field's default widget will be used. 276 """ 277 if not widget: 278 widget = self.field.widget 279 data, attrs = self.get_data_and_attrs(widget, attrs) 276 280 return widget.render(self.html_name, data, attrs=attrs) 277 281 278 282 def as_text(self, attrs=None): … … 331 335 return self.html_name 332 336 return '' 333 337 auto_id = property(_auto_id) 338 339 def __iter__(self): 340 data, attrs = self.get_data_and_attrs(widget, attrs) 341 for i in self.field.widget.iter(self.html_name, data, attrs=attrs): 342 yield i 343 -
django/newforms/widgets.py
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" -
tests/regressiontests/forms/widgets.py
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()