I'm working on a form with Formlib that looks like this:
from zope.schema import Choice, Float, Int, Date, TextLine
from Products.Five.formlib.formbase import PageForm
class ISimuladorForm(Interface):
"""
Zope Interface for the financial simulator for sofomanec.
"""
start_date = Date(title=_(u'Start Date'),
description=_(u'Loan start date.'),
required=False)
.
.
.
class SimuladorForm(PageForm):
form_fields = form.FormFields(ISimuladorForm)
The default input format for start_date is "mm/dd/yy", but users need to input the start_date in this format: "dd/mm/yy".
How do I change the default Date format for this Interface/Schema/Form?
You can use the
DateI18nWidgetinstead of the defaultDateWidget.It takes a
displayStyleattribute that controls the formatting of the value, and it'll use the request locale to format the date.displayStylemust be one of 'full', 'long', 'medium', 'short', or None and refers to the date formats defined inzope.i18n; the default is None, which I think means 'short' but this is unclear from the code.The exact formatting is taken from the request locale, which in turn is based on the language set for the Plone site by the portal_languages tool. Thus setting the language of the site also determines what date formats the
DateI18nWidgetwill use; these are defined in thezope.i18npackage in thelocales/datadirectory, in a set of XML files (look for the<dateFormats>element).If this isn't satisfactory then you'll have to create a custom browser widget. Your best bet is to subclass the
DateWidgetyourself and provide a new_toFormValuemethod to format the dates the way you want.