On 27/04/06, Michele Cella <[EMAIL PROTECTED]> wrote:
>
> Hi Ed,
>
> What about using a FieldSet to group related fields togheter? with CSS
> you can still a FieldSet as much as you need I think.
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?
> Keep in mind that when you use a FieldSet, that's a CompoundWidget, you
> receive as input a dictionary with a key for every field of the field
> set, so in end from the form you receive a nested dictionary.
>
> To prepolute such a form you need to pass a nested dictionary of the
> same structure at display/render as a value.
>
> Example:
>
> class PersonalDetailsFields(WidgetsList):
> name = TextField()
>
> class BankDetailsFields(WidgetsList):
> credit_card = TextField()
>
> class FormFields(WidgetsList):
> personal_details = FieldSet(fields=PersonalDetailsFields())
> credit_card = FieldSet(fields=BankDetailsFields())
>
> as input you receive two arguments personal_details and credit_card,
> they are two dicts:
>
> credit_card = {'name': 'michele'}
> personal_details = {'credit_card': '1231231234'}
>
> If you need to prepolutate such a form pass a value dict like this one:
>
> value = dict(credit_card={'name': 'michele'},
> personal_details={'credit_card': '1231231234'})
>
> and then:
>
> form.display(value=your_values_dict)
>
> Hope this helps, I think this is the best way since a FieldSet really
> helps here, or you can just cook your own CompoundFormField that
> provides headings, you just need a quick look at how the FieldSet is
> done, the template is easily accessible in this way:
>
> >>> from turbogears.widgets import FieldSet
> >>> print FieldSet.template
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):
class TableWithHeaders(RepeatingFormField):
template="""
<table xmlns:py="http://purl.org/kid/ns#">
<div py:for="repetition in repetitions" py:strip="True">
<tr py:if="legend">
<td colspan="2"><h1 py:content="legend"></h1></td>
</tr>
<div py:for="field in hidden_fields"
py:replace="field.display(value_for(field), **params_for(field))"
/>
<tr py:for="field in fields">
<td>
<label class="fieldlabel" for="${field.field_id}"
py:content="field.label" />
</td>
<td>
<span py:content="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>
</div>
</table>
"""
member_widgets = ["fields", "hidden_fields"]
params = ["legend"]
fields = []
hidden_fields = []
legend = None
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---