web/formwidgets.py
branchtls-sprint
changeset 1367 01bb5b727fe3
parent 1359 bef6891393d7
child 1389 ae58c2e7e1f7
equal deleted inserted replaced
1366:fd5bd1a63c3f 1367:01bb5b727fe3
   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