Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MINOR DateField documentation

  • Loading branch information...
commit 3588cefa30e59e7ba91e1a77c940aa3b21f30783 1 parent 4f90659
@chillu chillu authored
Showing with 23 additions and 2 deletions.
  1. +19 −2 docs/en/topics/i18n.md
  2. +4 −0 forms/DateField.php
View
21 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.
+
+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
-Form fields in the CMS are automatically set according to the profile settings for the logged-in user (`Member->DateFormat` and `Member->TimeFormat`).
+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
View
4 forms/DateField.php
@@ -14,6 +14,8 @@
* 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 @@
* 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
Please sign in to comment.
Something went wrong with that request. Please try again.