[EMAIL PROTECTED] wrote:
class ObsAddPeopleFields(widgets.WidgetsList):
lastname = widgets.TextField(label="lastname"
,validator=validators.NotEmpty)
firstname= widgets.TextField(label="firstname(s)"
,validator=validators.NotEmpty)
let's make a table form with it:
add_people_form = widgets.TableForm(fields=ObsAddPeopleFields()
,submit_text="save person")
and in the controllers.
I think the following is a good pattern, that I've seen here in the list:
class ObsAddPeople(object):
class Fields(widgets.WidgetsList):
lastname = widgets.TextField() # name is declared. default
label is guessed from name
firstname = widgets.TextField()
class Schema(turbogears.validators.Schema):
lastname = validators.NotEmpty # use validators.All to chain
other validators, like MaxLength
firstname = validators.NotEmpty
form = widgets.TableForm(fields=Fields(), validator=Schema(),
submit_text='save person')
Then, from your controllers, refer to form=ObsAndPeople.form in the dict
you return to the template, and in the @validate(form=ObsAndPeople.form)
decorator.
Me, I like to use explicit templates instead of TableForm, and explicit
SubmitButtons, but it makes no difference.
I'd like to do something like
add_people_form['lastname'].default='the lastname that we have guessed'
I usually do this:
params = {'value':{'lastname':'blabla'}}
then I pass form=TheFormClass.form and params=params to the template,
and display everything with form(**params)
params can also contain options to be send down to Select widgets,
repetitions number for Repetition widgets, and the like
Or, you could directly use form(value=value) if you have no need for
such options (but I bet you will)
so how can I do to touch the:
- default : so I can put a text in the textfield
The 'default' for widgets, is called 'value' in the case of forms, as
I've shown you above. This is used when the form is first displayed.
*If* there are validation errors upon submitting, the values redisplayed
are taken from the request (==the submitted values), so the 'value'
parameter is not used anymore.
- attrs : that I can change for e.g. the size
The attrs for widgets are usually specified inside the Field class, for
each widget. Just use attrs={'size':...., 'maxlength': ....}
The attrs for TableForm can, likewise, be passed to the TableForm
constructor.
thanks in advance for your help
Hope I was precise enough
Ced.
P.-S. does someone has a good reference for such things.
The printed book is quite good, but it doesn't contain every recipe.
More can be found on the wiki, I suppose.
There are many ways to operate forms, widgets, validators... it boils
down to (meta)classes and passing of dictionaries... so the best thing
would be to understand the base concepts. Try writing a few forms, then
take a look to widgets/forms.py to understand more of it.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---