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   2057 Views

Avatar
borriej

17 August 2010 at 10:27pm Community Member, 267 Posts

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

17 August 2010 at 10:45pm (Last edited: 17 August 2010 10:52pm), Community Member, 30 Posts

blubb

http://doc.silverstripe.org/datefield

http://paste2.org/p/953573

Avatar
borriej

17 August 2010 at 11:09pm Community Member, 267 Posts

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

17 February 2011 at 10:33pm Community Member, 50 Posts

Thank you, this was very helpful