From 3588cefa30e59e7ba91e1a77c940aa3b21f30783 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 25 May 2011 21:24:33 +1200 Subject: [PATCH] MINOR DateField documentation --- docs/en/topics/i18n.md | 21 +++++++++++++++++++-- forms/DateField.php | 4 ++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/docs/en/topics/i18n.md b/docs/en/topics/i18n.md index ef58bcdfe..feea71608 100644 --- a/docs/en/topics/i18n.md +++ b/docs/en/topics/i18n.md @@ -83,9 +83,26 @@ Date- and time related form fields support i18n ([api:DateField], [api:TimeField i18n::set_locale('ca_AD'); $field = new DateField(); // will automatically set date format defaults for 'ca_AD' $field->setLocale('de_DE'); // will not update the date formats - $field->setConfig('dateformat', 'dd.MM.YYYY'); // sets typical 'de_DE' date format + $field->setConfig('dateformat', 'dd. MMMM YYYY'); // sets typical 'de_DE' date format, shows as "23. Juni 1982" + +Defaults can be applied globally for all field instances through [api:DateField::set_default_config()] +and [api:TimeField::set_default_config()]. If no 'locale' default is set on the field, [api:i18n::get_locale()] +will be used. -Form fields in the CMS are automatically set according to the profile settings for the logged-in user (`Member->DateFormat` and `Member->TimeFormat`). +Important: Form fields in the CMS are automatically configured according to the profile settings for the logged-in user (`Member->Locale`, `Member->DateFormat` and `Member->TimeFormat`). This means that in most cases, +fields created through [api:DataObject::getCMSFields()] will get their i18n settings from a specific member + +The [api:DateField] API can be enhanced by JavaScript, and comes with +[jQuery UI datepicker](http://jqueryui.com/demos/datepicker/) capabilities built-in. +The field tries to translate the date formats and locales into a format compatible with jQuery UI +(see [api:DateField_View_JQuery::$locale_map_] and [api:DateField_View_JQuery::convert_iso_to_jquery_format()]). + + :::php + $field = new DateField(); + $field->setLocale('de_AT'); // set Austrian/German locale + $field->setConfig('showcalendar', true); + $field->setConfig('jslocale', 'de'); // jQuery UI only has a generic German localization + $field->setConfig('dateformat', 'dd. MMMM YYYY'); // will be transformed to 'dd. MM yy' for jQuery ## Adapting modules for i18n diff --git a/forms/DateField.php b/forms/DateField.php index c0629dc35..ad49330c8 100755 --- a/forms/DateField.php +++ b/forms/DateField.php @@ -14,6 +14,8 @@ require_once 'Zend/Date.php'; * Only useful in combination with {@link DateField_View_JQuery}. * - 'dmyfields' (boolean): Show three input fields for day, month and year separately. * CAUTION: Might not be useable in combination with 'showcalendar', depending on the used javascript library + * - 'dmyseparator' (string): HTML markup to separate day, month and year fields. + * Only applicable with 'dmyfields'=TRUE. Use 'dateformat' to influence date representation with 'dmyfields'=FALSE. * - 'dateformat' (string): Date format compatible with Zend_Date. * Usually set to default format for {@link locale} through {@link Zend_Locale_Format::getDateFormat()}. * - 'datavalueformat' (string): Internal ISO format string used by {@link dataValue()} to save the @@ -29,6 +31,8 @@ require_once 'Zend/Date.php'; * configuration accordingly. Changing the locale through {@link setLocale()} will not update the * `dateformat` configuration automatically. * + * See http://doc.silverstripe.org/sapphire/en/topics/i18n for more information about localizing form fields. + * * # Usage * * ## Example: German dates with separate fields for day, month, year