Jump to:

23493 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Default value for CalendarDateField

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

Page: 1
Go to End
Author Topic: 1318 Views
  • freefall
    Community Member
    5 Posts

    Default value for CalendarDateField Link to this post

    Hey Everyone,

    I have the following code for the CMS Fields:

    function getCMSFields() {
          // Get the parent fields
          $fields = parent::getCMSFields();
          // Others removed
          $fields->addFieldToTab("Root.Content.ArticleDetails", new CalendarDateField("Date", "Article date", date("d/m/Y")));
          // Others removed
          // return the fields
          return $fields;

    However, this is not setting the default value when I create a new item.

    I have followed this thread: http://silverstripe.org/data-model-questions/show/266116?start=0 however I get an error when adding the $default variable to my class, just underneath the static $db = array() block.

    Could someone please advise how to achieve this?


  • dalesaurus
    Community Member
    283 Posts

    Re: Default value for CalendarDateField Link to this post

    The ways outlined in the other thread should work to add to your $default static. If you are getting errors you must have something syntactically wrong.

    Another Option to default the date would be to make use of the onBeforeWrite() function to set your $this->Date = date('Y-m-d');
    Note the use of ISO-8601 date format.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.