1.

How Do I Pre-fill (some) Fields When I Display A Widgets-based Form?

Answer»

You provide a dictionary to the value parameter when you display the widget in the template. The dictionary must contain the the field names as keys and their preset value as values. You pass both the widget form object and the values dictionary to the template from your controller method.

Example:

# WIDGETS.py
myform = TableForm(
fields = [
widgets.TextField('name'),
widgets.TextField('email')
)
# controllers.py
from widgets IMPORT myform

class MyController(controllers.controller):
...
@EXPOSE('.templates.form_template')
def showform(SEFL, **kw):
form_values = dict(
name = "Joe Doe",
email = "joe@doe.com"
)
RETURN dict(form=myform, form_values=form_values)
<!-- form_template.kid -->
...
${form(value=form_values)}
...

You provide a dictionary to the value parameter when you display the widget in the template. The dictionary must contain the the field names as keys and their preset value as values. You pass both the widget form object and the values dictionary to the template from your controller method.

Example:

# widgets.py
myform = TableForm(
fields = [
widgets.TextField('name'),
widgets.TextField('email')
)
# controllers.py
from widgets import myform

class MyController(controllers.controller):
...
@expose('.templates.form_template')
def showform(sefl, **kw):
form_values = dict(
name = "Joe Doe",
email = "joe@doe.com"
)
return dict(form=myform, form_values=form_values)
<!-- form_template.kid -->
...
${form(value=form_values)}
...



Discussion

No Comment Found