197 """ |
197 """ |
198 type = 'checkbox' |
198 type = 'checkbox' |
199 |
199 |
200 def render(self, form, field): |
200 def render(self, form, field): |
201 name, curvalues, attrs = self._render_attrs(form, field) |
201 name, curvalues, attrs = self._render_attrs(form, field) |
202 options = [] |
|
203 for label, value in field.vocabulary(form): |
|
204 if value in curvalues: |
|
205 tag = tags.input(name=name, value=value, type=self.type, |
|
206 checked='checked', **attrs) |
|
207 else: |
|
208 tag = tags.input(name=name, value=value, type=self.type, |
|
209 **attrs) |
|
210 options.append(tag + label) |
|
211 return '<br/>\n'.join(options) |
|
212 |
|
213 |
|
214 class Radio(Input): |
|
215 """<input type='radio'>, for field having a specific vocabulary. One |
|
216 input will be generated for each possible value. |
|
217 """ |
|
218 type = 'radio' |
|
219 |
|
220 def render(self, form, field): |
|
221 name, curvalues, attrs = self._render_attrs(form, field) |
|
222 domid = attrs.pop('id', None) |
202 domid = attrs.pop('id', None) |
223 options = [] |
203 options = [] |
224 for i, (label, value) in enumerate(field.vocabulary(form)): |
204 for i, (label, value) in enumerate(field.vocabulary(form)): |
225 iattrs = attrs.copy() |
205 iattrs = attrs.copy() |
226 if i == 0 and domid is not None: |
206 if i == 0 and domid is not None: |
229 iattrs['checked'] = u'checked' |
209 iattrs['checked'] = u'checked' |
230 tag = tags.input(name=name, type=self.type, value=value, **iattrs) |
210 tag = tags.input(name=name, type=self.type, value=value, **iattrs) |
231 options.append(tag + label + '<br/>') |
211 options.append(tag + label + '<br/>') |
232 return '\n'.join(options) |
212 return '\n'.join(options) |
233 |
213 |
|
214 |
|
215 class Radio(CheckBox): |
|
216 """<input type='radio'>, for field having a specific vocabulary. One |
|
217 input will be generated for each possible value. |
|
218 """ |
|
219 type = 'radio' |
234 |
220 |
235 # javascript widgets ########################################################### |
221 # javascript widgets ########################################################### |
236 |
222 |
237 class DateTimePicker(TextInput): |
223 class DateTimePicker(TextInput): |
238 """<input type='text' + javascript date/time picker for date or datetime |
224 """<input type='text' + javascript date/time picker for date or datetime |