On Nov 10, 2006, at 5:22 PM, chiangf wrote:
>
> Thanks for the responses!
>
> Adam, perhaps I'm reading something that's not there, but you sound
> kind of reluctant? Is there some reason that I shouldn't override the
> constructor? I actually tried that for a bit but couldn't figure out
> why. But with your code, I think it'll work.
There's no problem in overriding the constructor to set initiali
parameter on then widget.
> I wanted to have everything finished before the actual rendering and
> then just return the whole thing in the dict that I send to the
> template, which is why I prefer the constructor way of doing it.
This can work well for most widgets, however, if some parameters are
request-dependant or you want to override them at display you should
place that logic inside "update_params". Take a look, for example, at
DataGrid to see how it "massages" the data and fields in
"update_params" so you can change the fields being displayed on a per-
request basis.
> Also, on a side note... is there any way of specifying the id of a
> widget? I tried doing widgets.SingleSelectField(label="My Field
> Label", id="myfieldid")
> but TG didn't seem to like that very much (it warned me and didn't use
> the id). Because I'm using Mochikit/JS to replaceChildNodes after
> getting a specific tag id.
Unfortunately there is no way of changing the id of a widget once
it's initialized or retrieve it unless you're inside "update_params"
like:
def update_params(self, d):
super(...).update_params(d)
id = d['field_id']
The id is computed from the widget's name and path so a field with id
'foo' inside a fieldset with name 'fs' inside a form named 'form'
would have an id of 'form_fs_foo'. However, this "path information"
can only be known when the widget is being displayed hence the
"update_params" limitiation I mentioned above.
This issue is something being addressed at TGWidgets (targeted for
inclusion in 1.1 although it can be used in 1.0 too), which let's you
know the *real* id of any widget at any time by accessing it's "id"
attribute (as shown in http://tgwidgets.toscat.net/tgwidgets.html).
Hopefully I'll have time somewhen soon to write some docs and
tutorials on TGW but right now I'm very busy on a project that's
using them.
HTH,
Alberto
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---