Ed Singleton wrote:
> On 26/04/06, Robin Haswell <[EMAIL PROTECTED]> wrote:
> > Ed Singleton wrote:
> > > I want to be able to use a header in in a TableForm.  I can see how to
> > > subclass Form to create a TableFormWithOptionalHeaders class that has
> > > a slightly different template, but I'm not sure how to create a new
> > > form widget that would just display a <h1>Section Title</h1> or maybe
> > > a <hr/>.
> >
> > I would recommend you modify TableForm to accept a "caption" attribute,
> > and stick a <caption py:if="caption" py:content="caption"/> at the top
> > of the table. Then submit a patch.
>
> Sorry, my previous email was slightly misleading.
>
> I want to be able to use multiple headers IN a TableForm's table.  It
> would produce something like the following, but with more fields in
> each section (obviously).
>
> <form>
>   <table>
>     <tr>
>       <td colspan="2"><h1>Personal Details</h1></td>
>     </tr>
>     <tr>
>       <td><label for="name">Name</label></td>
>       <td><input TYPE="text" ID="name" NAME="name" /></td>
>     </tr>
>     <tr>
>       <td colspan="2"><h1>Bank Details</h1></td>
>     </tr>
>     <tr>
>       <td><label for="creditcard">Credit Card</label></td>
>       <td><input TYPE="text" ID="creditcard" NAME="creditcard" /></td>
>     </tr>
>   </table>
> </form>

Hi Ed,

You've a pretty specific need here.

If you want to use a Widget I suggest you to encapsulate all things
(fields and layout that in this case is fields dependent) inside a
widget ready to use.

Example:

class MyFields(WidgetsList):
     name = TextField()
     creditcard = TextField()

class MyForm(TableForm):
    fields = MyFields()
    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">
        <tr>
             <td colspan="2"><h1>Personal Details</h1></td>
         </tr>
         <tr>
             <td><label for="name">Name</label></td>
             <td>
                  <div py:content="display_field_for('name')" />
                  <div py:content="error_for('name')" />
             </td>
         </tr>
         <tr>
             <td colspan="2"><h1>Bank Details</h1></td>
         </tr>
         <tr>
             <td><label for="creditcard">Credit Card</label></td>
             <td>
                  <div py:content="display_field_for('creditcard')" />
                  <div py:content="error_for('creditcard')" />
             </td>
         </tr>
             <tr>
                <td>&#160;</td>
                <td py:content="submit.display(submit_text)" />
            </tr>
        </table>
    </form>
    """

to keep in mind, this is only a basic example, since you're defining
fields content you just instantiate the Form and use it, you don't need
to pass the fields parameter in this case.

Also since you know in advance fields name you're going to use you
define labels by yourself and don't need to loop every field by just
use display_field_for(<field_name_here>) also display field for inside
a widget template already takes care of passing additional arguments
like value and params to the field.

Hope this helps.

Ciao
Michele


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

Reply via email to