21295 Posts in 5734 Topics by 2602 members
| Go to End | Next > | |
| Author | Topic: | 1163 Views |
-
[solved] DateFormat in HasOneComplexTableField

17 August 2011 at 10:21pm
I'm trying to format the date into 'HasOneComplexTableField' and 'FieldSet'. I only try to put the date in the right format in the CMS.
For the fieldset i've got this code:
function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push( new DateField( 'Date', 'Datum') ); //<-- This date has to be formatted into dd-MM-YYYY
$fields->push( new TextareaField( 'ShortDesc', 'Korte beschrijving' ) );
$fields->push( new TextareaField( 'LongDesc', 'Lange Beschrijving' ) );return $fields;
}For the 'HasOneComplexTableField' i've got this code:
$tablefield = new HasOneComplexTableField(
$this,
'MyCalendar',
'Calendar',
array(
'Date' => 'Datum',//<-- This date has to be formatted into dd-MM-YYYY
'ShortDesc' => 'Korte beschrijving',
'LongDesc' => 'Lange beschrijving'
),
'getCMSFields_forPopup'
);In my __config.php i did setup the i18n settings:
// Set the site locale
i18n::enable();
i18n::set_locale('nl_NL');
i18n::set_date_format('dd-MM-YYYY');I tried several things, like $fields->setConfig, but it returns the method 'setconfig' does not exist on 'FieldSet'. Is there any regular way to format these fields right?
-
Re: [solved] DateFormat in HasOneComplexTableField

17 August 2011 at 10:31pm
this is one thing I keep in a Utils class...
class Utils {
public static function MakeCalendarPopup($strFieldName,$strLabel) {
$df = new DateField($strFieldName,$strLabel);
$df->setConfig('showcalendar', true);
$df->setLocale('nl_NL');
$df->setConfig('dateformat', 'dd-MM-YYYY');
return $df;
}
}then in cmsfileds....
$f->replaceField('Date', Utils::MakeCalendarPopup('Date', 'Date:'));
-
Re: [solved] DateFormat in HasOneComplexTableField

17 August 2011 at 10:52pm
Thanks for the calendarpopup! The Fieldset works fine by now. The HasOneComplexTableField doesn't change to the right date. See attached image. Any idea?
-
Re: [solved] DateFormat in HasOneComplexTableField

17 August 2011 at 10:58pm
yep, using casting of summary fields like this...
public static $summary_fields = array (
...
'DateText' => 'Date',
...
);static $casting = array(
"DateText" => "Text",
);public function DateText() {
return <<add logic to format date top string here>>;
} -
Re: [solved] DateFormat in HasOneComplexTableField

17 August 2011 at 11:03pm
Also: using the ComplexTableField::setFieldFormatting() function will format the fields as they appear in the list (not the popup). Something like:
function formattedDate() {
//return formatted date
}$tablefield->setFieldFormatting(array(
'Date' => $this->formattedDate()
)); -
Re: [solved] DateFormat in HasOneComplexTableField

18 August 2011 at 12:21am
Sorry, stupid question: but how do i push the date into the function? $this->Date doesn't work.
-
Re: [solved] DateFormat in HasOneComplexTableField

18 August 2011 at 1:17am Last edited: 18 August 2011 1:17am
Not a stupid question at all
It has been a while, so I didn't quite remember how it went
It's the Calender object that knows its own date, so this should go into your Calendar class:
public function getFormattedDate() {
return date('d-m-Y', strtotime($this->Date)); // replace with however you want to do it
}Next for your ComplexTableField:
$tablefield->setFieldFormatting(array(
'Date' => '$FormattedDate')
));The code '$FormattedDate' will be eval-ed for the Calender object, hence the quotes... So now I remember
-
Re: [solved] DateFormat in HasOneComplexTableField

18 August 2011 at 2:34am
Hmm. $this->Date still doesn't work
. Is there an other option to get the date from the HasOneComplexTableField?
| 1163 Views | ||
| Go to Top | Next > |


