Wierd to the max....

I think I would totally do this:
Outside the controller:
form = TableForm(
    fields = [wid.RepeatingFieldSet('fractions',
        fields = [
            wid.SingleSelectField('module',options=[('','')]),
            wid.TextField('amount',validator=val.Money)])],
    submit_text = 'submit')

In the controller:
formData = {
   'value': invoice,
   'repetitions': {'fractions': 2},
   'options': {
       'fractions': [{'module':[('foo','foo')]},
                       {'module':[('foo','foo'), ('foo2', 'foo2')]}]}
}

return dict(form=form, formData=formData)

And in the template:
${form(**formData)}


If I am correct your original mistake was to not make options for each
repetition.
-Ian


And as your repetitions increase you have to add more options to

On 2/16/07, Marco Mariani <[EMAIL PROTECTED]> wrote:
>
> Diez B. Roggisch wrote:
> > Here we have the problem. params is a passed dictionary, _not_ a dictionary
> > passed via ** as arguments!!!
> >
> > I'm not exactly sure which magic makes 2) work, but I'm pretty sure my
> > solution works if you do it like this:
> >
> > ${form(params=params)}
> >
> yes, it's my fault. I was meaning to pass value, params and such
> together to the template and the form, and I've fixed it now
>
> So, this test case should work, right?
>
>
> >     myform = wid.TableForm( fields = [
> > wid.SingleSelectField('foo',options=[('','')]) ])
> >
> >     @expose(template='erp.templates.test')
> >     def test(self):
> >         params = {
> >             'foo':{'options':[('baz','baz')]}
> >             }
> >
> >         return dict(form=self.myform,params=params)
>
> --test.kid--
> ...
> ${form(params=params)}
> ...
>
>
> SingleSelectField.update_params()  is called with
> d={....,params={'options':[('baz','baz')]}...,options=[('','')]...}
>
> Of course, the updated options never make it into self.options. There is
> nothing like self.__dict__.update(**d['params']), after all.. because we
> need to reuse the same widget instance across threads.
>
> I put a breakpoint in Widget.display(), just before returning the
> template's ElementTree.Element:
>
>
> > (Pdb) self
> > SingleSelectField(name='foo', convert=False, css_classes=[], attrs={},
> > field_class='singleselectfield', options=[('', '')])
> > (Pdb) l
> > 260             params["value"] = to_unicode(self.adjust_value(value,
> > **params))
> > 261             self.update_params(params)
> > 262             # update_data has been deprecated
> > 263             self.update_data(params)
> > 264             import pdb; pdb.set_trace()
> > 265  ->         return view.engines.get('kid').transform(params,
> > self.template_c)
> > 266
> > 267         def render(self, value=None, format="html", **params):
> > 268             """
> > 269             Exactly the same as display() but return serialized
> > output instead.
> > 270             Useful for debugging or to display the widget in a
> > non-Kid template like
> > (Pdb) params
> > {'convert': False, 'name': 'foo', 'error': None, 'field_id':
> > 'form_foo', 'value': None, 'label': 'Foo', 'params': {'options':
> > [('baz', 'baz')]}, 'attrs': {}, 'css_classes': [], 'help_text': None,
> > 'field_class': 'singleselectfield', 'options': [('', '', {'selected':
> > 'selected'})], 'grouped_options': [(None, [('', '', {'selected':
> > 'selected'})])]}
> Here, we have
>
> 1) params['params']['options']  ... which means... i'm not sure
>
> 2) params['options'] is ignored anyway, because the template uses
> params['grouped_options'] and completely ignores 'options'. So if there
> is any updating of options, it must be done before grouped_options is
> constructed
>
>
>
> Back to the repeating widget, what does this mean?
> Basically, the only way to update the options is pass them outside
> params. And if I do that, they are not passed down through the repeating
> widget.
>
> uhm.
>
> I guess I will use
>
> > class MySelectField(wid.SingleSelectField):
> >     def update_params(self, d):
> >         if d.get('params',{}).get('options'):
> >             d['options'] = d['params']['options']
> >         return super(MySelectField, self).update_params(d)
>
>
> This works. If there is any easier way, I'd be glad to know, otherwise
> it should probably be handled by the FAQ or by TG1.1
>
>
> I can also address specific repetitions
> The correct syntax is:   params = {'outerwidget':
> [{'repeatedwidget':{'options':[...]}...},{'repeatedwidget'....}]}.
>
>
> Thanks again
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to