On 7/4/07, alex23 <[EMAIL PROTECTED]> wrote:
>
> Hey everyone,

Hey Alex,

[...]

> Often I'm finding I'm wanting the default options of widgets to be set
> based on the values of parent/object. I end up with lots of form
> factories that accept the parent/object pair as arguments and
> construct the relevant form:
>

Argh :)

you should _only_ create a form once and then set its value and
defaults by passing value and options arguments to its render method.

look at:
http://docs.turbogears.org/1.0/SimpleWidgetForm#id6

It's not much but a beginning of an explanation. You are actually
touching one of the parts I find really tricky in TG's widgets (and
one of the things that are mostly changed in ToscaWidget for example)

for more info look also in turboblog:
http://turboblog.devjavu.com/projects/turboblog/browser/trunk/turboblog/formdisplay.py

and its usage here:

http://turboblog.devjavu.com/projects/turboblog/browser/trunk/turboblog/admin/admin_forms.py#L138

where I set the method onto my widget and then in the template here:

http://turboblog.devjavu.com/projects/turboblog/browser/trunk/turboblog/templates/admin/adminform.kid#L12

the "params" come from the controller here:
http://turboblog.devjavu.com/projects/turboblog/browser/trunk/turboblog/admin/manage_users.py#L86

I know it can be confusing, but tell us if you succeed in making sense
of all this and don't bother too much with my display_with_params
function this is just an ugly add-on on top of the normal display
method to help me (At least I thought it would help at the time I
created it, but I now am sure I'll remove it completely in favor of
plain display).

I need to catch a plane so I can't make a real personnalised
explanation, but if nobody did give you a helping hand by tonight I'll
try to continue and add a better explanation...

> I'm finding the whole coercing of data into appropriate states
> actually pretty confusing. I only just found out about jsonify, but
> can't find much in the way of useful information. If I have a single
> form that allows for - say - the creation of a client & an associated
> contact at the same time, I tend to end up defining properties on the
> parent that control the creation of the child. Which means the model
> ends up knowing what to expect from the forms, something else I'd
> rather avoid. Would it be more appropriate to cooerce the data into an
> object via a validator?

Short answer: yes
I don't know if it is sufficient to help you:
http://docs.turbogears.org/1.0/FormValidationWithSchemas

Regards,
Florent.

--~--~---------~--~----~------------~-------~--~----~
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