On 6/5/06, Alberto Valverde <[EMAIL PROTECTED]> wrote:


I'm not sure I understand you correctly, or more precisely,
understand concretely where you're lost at so I'll try to guess...

i'm sorry i believe i transmit my mess on the message.
So far I undestand widgets are a way to programatically create reusable view components, which at some point have some logic (but it's 100% view logic)

now widgets can have other widgets inside and that's where my problem is. Because I'm not sure if I have to make a widget and then put stuff in there (like wxwidgets/Swing/SWT,etc.) and build some kind of tree.

or do something like ASP/JSP tags where you have a "complex tag" that will eventually be process as text.

If you need a form with one of the default templates you can subclass
ListForm or TableForm:

but that's not the case with other widgets like the GridView where you create instances.

class MyForm(XXXForm):
        fields = [
                TextField("username"),
                SingleSelectField("gender"),
                ....
        ] # This list can also be a WidgetsList if you prefer it's syntax
        validator = MySchema() # Individual validators can also be attached
to each individal FormField widget

ok I though that was the Idea but then the examples extend from CoreWD not the XXXform class as I expected

To use it, you need to display it in a template and to receive it's
input (and validate it). Do:

myform = MyForm()
@validate(form=myform)
@error_handler(method_wich_displayed_the_form)
@expose()
def controllermethod(self, **kw):
        # kw holds *valid* and coerced values.
        .....

If you need more control over the layout, just subclass 'Form' and
give it a custom template (I'd advise you to copy-paste TableForm and
replace everything between <form> and </form>).

umm yes I think that's what I need here.

Use display_field_for, and error_for to access the fields and their errors:

class MyForm(form):
        fields = ....
        template = """
        <form .... >
        ${display_field_for("username")} <br />
        <span class="error" py:if="error_for('username')"
py:content="error_for('username')" />
        .....
        </form>
        """

Some pointers:

http://trac.turbogears.org/turbogears/wiki/SimpleWidgetForm

ummm though that was outdated.

http://trac.toscat.net/TGTutorial/file/trunk/tgsimpleblog/forms.py

will take a look thanks

HTH,
Alberto



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