On 02/05/06, Michele Cella <[EMAIL PROTECTED]> wrote:
>
> Ed Singleton wrote:
> >
> > 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).
> >
>
> No, RepeatingFieldSet displays n repetitions of the *same* FieldSet.
> Yes, building and reusing fieldsets is indeed a nice way of doing
> things IMHO, and widgets support this quite well.
>
> > > 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).
> >
>
> Ok, you may want to use a different name than TableForm and avoid
> repeating everything apart from templates if you inherit form it
> (TableFormWithHeaders(TableForm)), params and such are all
> automatically inherited from your bases classes. ;-)
Well, this is what I've got so far:
A TableForm that takes FieldSets and displays the legends as a heading.
A Form that takes several fieldsets and displays them.
Many thanks for your (patient) help on this:
from turbogears.widgets import *
class MultiFieldset(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="fieldset in fieldsets"
py:replace="fieldset.display(value_for(fieldset),
**params_for(fieldset))"
/>
</form>
"""
params = ["fieldsets"]
fieldsets = []
class MultiFieldsetTable(TableForm):
template = """
<form xmlns:py="http://purl.org/kid/ns#"
name="${name}"
action="${action}"
method="${method}"
class="tableform"
py:attrs="form_attrs"
>
<table py:attrs="table_attrs">
<tbody py:for="fieldset in fieldsets" py:strip="True">
<tr py:if="fieldset.legend" colspan="2">
<h1 py:content="fieldset.legend">This is a Heading</h1>
<div py:for="field in hidden_fields"
py:replace="field.display(value_for(field),
**params_for(field))"
/>
</tr>
<tr py:for="i, field in enumerate(fieldset.fields)"
class="${i%2 and 'odd' or 'even'}"
>
<td>
<label class="fieldlabel"
for="${field.field_id}" py:content="field.label" />
</td>
<td>
<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>
</tbody>
</table>
</form>
"""
params = ["fieldsets"]
fieldsets = []
class PersonalDetailsFields(WidgetsList):
name = TextField()
class BankDetailsFields(WidgetsList):
credit_card = TextField()
class testMultiFieldset(WidgetsList):
personal_details = FieldSet(fields=PersonalDetailsFields(),
legend="Personal Details")
credit_card = FieldSet(fields=BankDetailsFields(),
legend="Financial Details")
tMF = MultiFieldset(fieldsets=testMultiFieldSet)
tMFT = MultiFieldsetTable(fieldsets=testMultiFieldSet)
tMF.render()
tMFT.render()
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---