On 04/06/2006, at 7:21, Jorge Vargas wrote:
> hi everyone I have been trying to get a FormWidget to work and
> can't find any docs on it.
>
> and google is not helping since the term is so popular...
>
> from the code/wiki/mailing list.
>
> I think that I need to create a subclass of it (but i'm not sure
> which class)
>
> or
>
> send some values in but those seems to be a dict of widgets but i
> don't know how.
>
> so i'm kind of lost.
>
>
> right now my goal is to make a form that will let users create
> input that eventually will become an instance if 2 sqlobjects (and
> no I don't need fastdata or CRUD) I'm doing some processing inside
> my code.
I'm not sure I understand you correctly, or more precisely,
understand concretely where you're lost at so I'll try to guess...
If you need a form with one of the default templates you can subclass
ListForm or TableForm:
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
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>). 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
http://trac.toscat.net/TGTutorial/file/trunk/tgsimpleblog/forms.py
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
-~----------~----~----~----~------~----~------~--~---