So, this is my problem..
I need to generate forms dynamically with input names that may change
in some circumstances. This means that i can't use pre-determined
method arguments to retrieve the input from these forms.
Even if i did these forms are often too big (with many input fields)
and i can't keep mapping all of them with method arguments.
So i (probably) need widgets... TableForm widgets (?)... I've tried
some things (from the book)...

I did something like:
class TableFormDesc(widgets.WidgetsList):
    fields = []
    options = {"option1":"value1","option2":"value2"} #just for test
    for option in options.keys():
         fields +=
[widgets.TextField(option,default=options[option])]
    print fields
    name = "Table Form"
    full_class_name = "turbogears.widgets.TableForm"
    for_widget = widgets.TableForm("TableForm",
                           fields,
                           action="%s/save" % full_class_name,
                           submit_text="Submit")
    template = """
    <div>
        ${for_widget.display(disabled_fields=["reserved"])}
    </div>
    """

    @expose()
    @validate(form=name)     #this is probably wrong...
    def save(self, **kw):
        return """Received data from TableForm:<br />%r""" % kw
    save = expose()(save)


On the template i have:
...
<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 border="0" cellspacing="0" cellpadding="2"
py:attrs="table_attrs">
                    <tr py:for="i, field in enumerate(fields)"
                        class="${i%2 and 'odd' or 'even'}"
                                        >
                        <th>
                            <label class="fieldlabel" for="${field.field_id}"
py:content="field.label" />
                        </th>
                        <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>
                    <tr>
                        <td> </td>
                        <td py:content="submit.display(submit_text)" />
                    </tr>
                </table>
            </form>
...

I confess that i still don't understand all code presented above, so
examples would be very welcome.

The output error is:
Traceback (most recent call last):
  File "./start-yat.py", line 23, in ?
    from yat.controllers import Root
  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
python2.4/site-packages/Myghty-1.1-py2.4.egg/myghty/importer.py", line
54, in import_module
    return builtin_importer(name, globals, locals, fromlist)
  File "/Users/blackthorne/Desktop/yat/yat/controllers.py", line 67,
in ?
    class TableFormDesc(widgets.WidgetsList):
  File "/Users/blackthorne/Desktop/yat/yat/controllers.py", line 85,
in TableFormDesc
    submit_text="Submit Me")
  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
python2.4/site-packages/TurboGears-1.0.2.2-py2.4.egg/turbogears/
widgets/meta.py", line 169, in widget_init
    validator = generate_schema(self.validator, widgets)
  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
python2.4/site-packages/TurboGears-1.0.2.2-py2.4.egg/turbogears/
widgets/meta.py", line 275, in generate_schema
    schema = copy_schema(schema)
  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
python2.4/site-packages/TurboGears-1.0.2.2-py2.4.egg/turbogears/
widgets/meta.py", line 212, in copy_schema
    new_schema.pre_validators = schema.pre_validators[:]
AttributeError: 'list' object has no attribute 'pre_validators'

Thanks, best regards


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