On 02/05/06, Michele Cella <[EMAIL PROTECTED]> wrote:
>
> Ed Singleton wrote:
> >
> > I guess so, but I really would like to work out how to create my own
> > form fields. Is there no explanation of how the widgets work
> > internally?
> >
>
> Not much ATM :-(, anyway keep this in mind usually what you need are
> more parameters to customize the widget behavior at display/render
> time, to do this *all* that you need is listing an additional parameter
> in params, this tells the Widget system that this is attribute is
> special and you can update it at construction or render/display and
> it's available inside the template or update_params, you don't need to
> override init or update_params to manage it.
>
> Example:
>
> class FooBar(Widget):
> template = """<div>${foo}</div>
> params = ["foo"]
> foo = "Hello"
Okay, I probably should have been able to work that much out (I think
I also had a typo in my test version which didn't help). That much
certainly is quite nice and easy.
Thanks for all your help on this. Is it documented anywhere? If not
should I try to summarise what I've worked out so far for the wiki?
> >
> > Thanks for this. It was enough info for me to do a rough draft of
> > what I want. It's untested and needs more stuff adding, but it's
> > basically what I want. (Though I really want to know how I add extra
> > parameters and stuff). It's the RepeatingFieldSet with a different
> > template (uses the legend for the header content):
> >
>
> Are you sure that what you want is a repeating widget? this widget uses
> a repetitions parameter to display one or more repetitions of the same
> widget and to validate them.
No not at all sure. I assumed the RepeatingFieldSet iterated through
some fieldsets, displaying each one. I do like the idea of building
FieldSets and then constructing a form out of a bunch of fieldsets
(Contact Info, or similar will be on a lot of forms and I can just
insert that fieldset in my form rather than copy and paste it each
time).
> I think you don't want this in your case...
Probably not, but I do now want to do something with groups of
fieldsets rather than with a single long form with headers inserted.
However I have produced this, which seems to work fine for the moment
(I'm going to go look more at fieldsets now).
class Header(FormField):
"A simple header for a form."
template = """
<h1 xmlns:py="http://purl.org/kid/ns#"
class="${field_class}"
py:content="heading"
>Heading
</h1>
"""
params = ["attrs", "heading"]
heading = "default heading"
attrs = {}
class TableForm(Form):
template = """
<form xmlns:py="http://purl.org/kid/ns#"
name="${name}"
action="${action}"
method="${method}"
class="tableform"
py:attrs="form_attrs"
>
<div py:for="field in hidden_fields"
py:replace="field.display(value_for(field), **params_for(field))"
/>
<table>
<tr py:for="i, field in enumerate(fields)"
class="${i%2 and 'odd' or 'even'}"
>
<td py:if="hasattr(field, 'heading')" colspan="2">
<span py:replace="field.display(**params_for(field))" />
</td>
<td py:if="not hasattr(field, 'heading')">
<label class="fieldlabel" for="${field.field_id}"
py:content="field.label" />
</td>
<td py:if="not hasattr(field, 'heading')">
<span py:replace="field.display(value_for(field),
**params_for(field))" />
<span py:if="error_for(field)" class="fielderror"
py:content="error_for(field)" />
<span py:if="field.help_text" class="fieldhelp"
py:content="field.help_text" />
</td>
</tr>
<tr>
<td> </td>
<td py:content="submit.display(submit_text)" />
</tr>
</table>
</form>
"""
params = ["table_attrs"]
table_attrs = {"border": 0,
"cellspacing": 0,
"cellpadding": 2}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---