Changeset 191

Show
Ignore:
Timestamp:
03/14/06 10:54:44 (3 years ago)
Author:
matt
Message:

Make CheckboxMultiChoice? cope with deferred options.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/forms/__init__.py

    r186 r191  
    44 
    55 
    6 version_info = (0, 7, 0
     6version_info = (0, 7, 1
    77version = '.'.join([str(i) for i in version_info]) 
    88 
  • trunk/forms/examples/selections.py

    r190 r191  
    2020    # Let's defer it, just for fun. 
    2121    return defer.succeed(strings) 
    22      
     22 
    2323# A different "none" option tuple 
    2424differentNone = ('none value', '- select -') 
     
    4141                forms.widgetFactory(forms.SelectChoice, options=dates)) 
    4242        form.addField('multipleStrings', forms.Sequence(forms.String()), 
    43                 forms.widgetFactory(forms.CheckboxMultiChoice, options=strings)) 
     43                forms.widgetFactory(forms.CheckboxMultiChoice, 
     44                    options=data_strings)) 
    4445        form.addField('multipleDates', forms.Sequence(forms.Date()), 
    4546                forms.widgetFactory(forms.CheckboxMultiChoice, options=dates)) 
  • trunk/forms/widget.py

    r180 r191  
    624624 
    625625    def _renderTag(self, ctx, key, values, converter, disabled): 
    626  
    627         # loops through checkbox options and renders 
    628         for n,item in enumerate(self.options): 
    629             optValue = iforms.IKey(item).key() 
    630             optLabel = iforms.ILabel(item).label() 
    631             optValue = converter.fromType(optValue) 
    632             optid = (keytocssid(ctx.key),'-',n) 
    633             checkbox = T.input(type='checkbox', name=key, value=optValue, id=optid ) 
    634             if optValue in values: 
    635                 checkbox = checkbox(checked='checked') 
    636             if disabled: 
    637                 checkbox = checkbox(class_='disabled', disabled='disabled') 
    638             yield checkbox, T.label(for_=optid)[optLabel], T.br() 
     626        def renderer(ctx, options): 
     627            # loops through checkbox options and renders 
     628            for n,item in enumerate(options): 
     629                optValue = iforms.IKey(item).key() 
     630                optLabel = iforms.ILabel(item).label() 
     631                optValue = converter.fromType(optValue) 
     632                optid = (keytocssid(ctx.key),'-',n) 
     633                checkbox = T.input(type='checkbox', name=key, value=optValue, id=optid ) 
     634                if optValue in values: 
     635                    checkbox = checkbox(checked='checked') 
     636                if disabled: 
     637                    checkbox = checkbox(class_='disabled', disabled='disabled') 
     638                yield checkbox, T.label(for_=optid)[optLabel], T.br() 
     639        # Let Nevow worry if self.options is not already a list. 
     640        return T.invisible(data=self.options)[renderer] 
    639641 
    640642    def render(self, ctx, key, args, errors):