Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

DateField in SS 2.4.1


Reply


4 Posts   2097 Views

Avatar
borriej

Community Member, 267 Posts

17 August 2010 at 10:27pm

Hello,

It used to be so easy in SS 2.3.7. Now it's not working in SS 2.4.1

Problem:
When entering a date in the CMS, like 08/16/2010

It is - after save - converted to: Aug 16, 2010

But when you edit the page, and click save again you get the error:
'validation failed'

This is because the date is as text, because when i enter the date in numbers again, it will save.

How do i fix this/ Keep the date in numbers??

Thanks!

the code: http://paste2.org/p/953549

Avatar
Zauberfisch

Community Member, 30 Posts

17 August 2010 at 10:45pm

Edited: 17/08/2010 10:52pm

blubb

http://doc.silverstripe.org/datefield

http://paste2.org/p/953573

Avatar
borriej

Community Member, 267 Posts

17 August 2010 at 11:09pm

Working!
Complete code

<?php
/**
* Defines the ArticlePage page type
*/
class ArticlePageextends Page {
static $db = array(
'Date' => 'Date',
'Author' => 'Text'
);

static $has_one = array(
);

   function getCMSFields() {
      $fields = parent::getCMSFields();
      
      $DateField = new Datefield('Date','Date');
      $DateField->setConfig('showcalendar', true);
      $DateField->setConfig('dateformat', 'dd-MM-YYYY');

      $fields->addFieldToTab('Root.Content.Main', $DateField, 'Content');   
      $fields->addFieldToTab('Root.Content.Main', new TextField('Author'), 'Content');
      
      return $fields;
   }

}

class ArticlePage_Controller extends Page_Controller {

}

?>

Avatar
web2works

Community Member, 50 Posts

17 February 2011 at 10:33pm

Thank you, this was very helpful