On Aug 18, 2006, at 10:09 AM, roopesh wrote:
>
> Atlast I found out how
>
> In your kid page include :
>
> <LINK MEDIA="all"
> HREF="/tg_widgets/turbogears.widgets/calendar/calendar-system.css"
> TYPE="text/css" REL="stylesheet"/>
> <SCRIPT SRC="/tg_widgets/turbogears.widgets/calendar/calendar.js"
> TYPE="text/javascript"></SCRIPT>
> <SCRIPT SRC="/tg_widgets/turbogears.widgets/calendar/calendar-
> setup.js"
> TYPE="text/javascript"></SCRIPT>
> <SCRIPT
> SRC="/tg_widgets/turbogears.widgets/calendar/lang/calendar-en.js"
> TYPE="text/javascript"></SCRIPT
>
> Create the calendar instance
>
> <?python
> from turbogears import widgets
> cal_picker1 = widgets.CalendarDatePicker(name="from_date")
> cal_picker2 = widgets.CalendarDatePicker(name="till_date")
> ?>
>
> <fieldset class="borderless">
> <div>
> From Date
> ${cal_picker1()}
> Till Date
> ${cal_picker2()}
> </div>
> </fieldset>
>
> Regards
> Roopesh
The TG Widgets way of doing it would be:
from turbogears.widgets import *
form = TableForm(fields=[
FieldSet("dates", css_classes=["borderless"], fields=[
CalendarDatePicker("from_date", label="From Date"),
CalendarDatePicker("till_date", label="Till date")
]
])
class Root(RootController):
@expose("templates.mytemplate")
def show_form(self):
return dict(form=form)
# validate input using our form
@validate(form=form)
#If validation fails, redisplay the form with errors
@error_handler(show_form)
@expose()
def save_data(self, dates):
# the fieldset in the form creates a nested structure with both
dates
# in the dates dict
#process dates["from_date"], dates["till_date"]
--- mytemplate.kid ---
${form(action="save_data", submit_text="Send me those dates!!")}
The advantages widgets provide in this example:
1) Input can be validated coercing input to python objects. This
makes sure dates["till_date"] and dates["from_date"] are datetime
objects when they reach the controller's body. You can define custom
validators to make sure all data that reaches the controller is valid
accoridng to the apps criteria ("is from_date < till_date?").
The "error_handler" decorator will branch to "show_form" if
validation fails which will cause the form to be redisplayed with
error messages beside the fields.
2) CSS and JS links don't need to be explicitly included in the
template as all these resources get pulled from the widgets that the
controller methods return.
The main disadvantage is that you have no control over the form's
final layout (beside the fields' order and what can be accomplished
with CSS). However, you can override the form's template with your
own (take the built in templates at turbogears/widgets/forms.py for
inspiration) and pass it when instantiating the form:
form = Form(template="<form ....>...</form>")
or
form = Form(template="templates.myform")
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
-~----------~----~----~----~------~----~------~--~---