Permalink
Browse files

ENHANCEMENT Allow locale/dateformat specific reordering of day, month…

…, year input fields in DateField (from r99361)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102860 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
1 parent 6227478 commit 498c075ece581919930dc9634682e90584877989 @chillu chillu committed Apr 14, 2010
Showing with 10 additions and 7 deletions.
  1. +10 −7 forms/DateField.php
View
@@ -48,6 +48,7 @@ class DateField extends TextField {
protected $config = array(
'showcalendar' => false,
'dmyfields' => false,
+ 'dmyseparator' => '&nbsp;<span class="separator">/</span>&nbsp;',
'dateformat' => null,
'datavalueformat' => 'yyyy-MM-dd',
'min' => null,
@@ -101,13 +102,15 @@ function Field() {
$fieldYear->addExtraClass('year');
$fieldYear->setMaxLength(4);
- // TODO Locale specific ordering of fields
- $sep = '&nbsp;<span class="separator">/</span>&nbsp;';
- $html = $fieldDay->Field() .
- $sep .
- $fieldMonth->Field() .
- $sep .
- $fieldYear->Field();
+ // order fields depending on format
+ $sep = $this->getConfig('dmyseparator');
+ $format = $this->getConfig('dateformat');
+ $fields = array();
+ $fields[stripos($format, 'd')] = $fieldDay->Field();
+ $fields[stripos($format, 'm')] = $fieldMonth->Field();
+ $fields[stripos($format, 'y')] = $fieldYear->Field();
+ ksort($fields);
+ $html = implode($sep, $fields);
}
// Default text input field
else {

0 comments on commit 498c075

Please sign in to comment.