I have attached a simple data object and model admin using a couple of dates. There is also validation to ensure blank values are not entered.
1)The dates are converted in some way that gives the wrong date... I select 1st April 2010 in the calendar pop up, then I get '01/04/2010' written into the text input next to it. then when I click 'Add' that value changes to 'Jan 4, 2010'
2)validation fails for the second DateField? as the validator has nothing in the data for that item.
I have the following in mysite/_config.php...
i18n::set_locale('en_GB');
(tested in firefox)
Code follows, any help with this would be much appreciated :)
TestTable.php
<?php
class TestTable extends DataObject
{
static $db = array(
'Name' => 'Text',
'DateFrom' => 'Date',
'DateTo' => 'Date',
);
public static $summary_fields = array (
'Name' => 'Name',
);
function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->replaceField('Name',new TextField('Name'));
$df1 = new DateField('DateFrom', 'DateFrom');
$df1->setConfig('showcalendar', true);
$fields->replaceField('DateFrom', $df1);
$df2 = new DateField('DateTo', 'DateTo');
$df2->setConfig('showcalendar', true);
$fields->replaceField('DateTo', $df2);
return $fields;
}
function getCMSValidator()
{
return new TestValidator();
}
}
TestValidator.php
<?php
class TestValidator extends Validator
{
function javascript()
{
return false;
}
function php($data)
{
$bRet = true;
if (empty($data['DateTo']))
{
$this->validationError(
'DateTo',
'DateTo is required',
"required"
);
$bRet = false;
}
if (empty($data['DateFrom']))
{
$this->validationError(
'DateFrom',
'DateFrom is required',
"required"
);
$bRet = false;
}
return $bRet;
}
}
TestAdmin.php
<?php
class TestAdmin extends ModelAdmin
{
static $managed_models = array(
'TestTable',
);
static $url_segment = 'testadmin';
static $menu_title = 'Test Admin';
static $model_importers = array();
}