201 class Radio(Input): |
201 class Radio(Input): |
202 """<input type='radio'>, for field having a specific vocabulary. One |
202 """<input type='radio'>, for field having a specific vocabulary. One |
203 input will be generated for each possible value. |
203 input will be generated for each possible value. |
204 """ |
204 """ |
205 type = 'radio' |
205 type = 'radio' |
206 setdomid = False # by default, don't set id attribute on radio input |
|
207 |
206 |
208 def render(self, form, field): |
207 def render(self, form, field): |
209 name, curvalues, attrs = self._render_attrs(form, field) |
208 name, curvalues, attrs = self._render_attrs(form, field) |
|
209 domid = attrs.pop('id', None) |
210 options = [] |
210 options = [] |
211 for label, value in field.vocabulary(form): |
211 for i, (label, value) in enumerate(field.vocabulary(form)): |
|
212 iattrs = attrs.copy() |
|
213 if i == 0 and domid is not None: |
|
214 iattrs['id'] = domid |
212 if value in curvalues: |
215 if value in curvalues: |
213 tag = tags.input(name=name, type=self.type, value=value, |
216 iattrs['checked'] = u'checked' |
214 checked='checked', **attrs) |
217 tag = tags.input(name=name, type=self.type, value=value, **iattrs) |
215 else: |
218 options.append(tag + label + '<br/>') |
216 tag = tags.input(name=name, type=self.type, value=value, **attrs) |
|
217 tag += label + '<br/>' |
|
218 options.append(tag) |
|
219 return '\n'.join(options) |
219 return '\n'.join(options) |
220 |
220 |
221 |
221 |
222 # javascript widgets ########################################################### |
222 # javascript widgets ########################################################### |
223 |
223 |