21277 Posts in 5728 Topics by 2599 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1166 Views |
-
Default value for CalendarDateField

16 November 2009 at 6:45pm
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?
Cheers,
Justin -
Re: Default value for CalendarDateField

17 November 2009 at 5:47am
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.
| 1166 Views | ||
|
Page:
1
|
Go to Top |


