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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

SS3: Show Date Picker in CMS datagrid


Go to End


2 Posts   968 Views

Avatar
Fraser

Community Member, 48 Posts

14 September 2012 at 11:46am

I have a datagrid allowing the user to add events to an event page.

On it, I have 2 date fields so they can specify a start and end date. These fields do not show the date picker unless I comment out a line from DateField.js in Sapphire/javascript (line 12 - if(!config.showcalendar) return;).

Is there anyway to get the date picker to show without tampering with the core?

<?php
class Event extends DataObject{
	public static $db = array(
		'Title' => 'Varchar(255)',
  		'StartDate' => 'Date',
  		'EndDate' => 'Date',
  		'Summary' => 'Text',
  		'Content' => 'HTMLText'
 	);

 	static $has_one = array( 
		'WhatsOnCategory' => 'WhatsOnCategory',
		'EventImage' => 'Image'
	);

 	public static $summary_fields = array(
  		'Title' => 'Title'
 	);
 	
 	public static $default_sort='StartDate';

 	public function getCMSFields() {
	  	return new FieldList(
	   		new TextField('Title', 'Title'),
	   		new DateField('StartDate', 'StartDate'),
	   		new DateField('EndDate', 'EndDate'),
	   		new TextField('Summary', 'Summary'),
	   		new HTMLEditorField('Content', 'Content'),
	   		new UploadField('EventImage','Image')
	  	);
	}
}

Avatar
Devlin

Community Member, 344 Posts

15 September 2012 at 12:56am

public function getCMSFields() {
	$fields = array();

	$fields[] = new TextField('Title', 'Title');
	$fields['StartDate'] = new DateField('StartDate', 'StartDate');
	$fields['StartDate']->setConfig('showcalendar', true);
	$fields['EndDate'] = new DateField('EndDate', 'EndDate');
	$fields['EndDate']->setConfig('showcalendar', true);
	$fields[] = new TextField('Summary', 'Summary');
	$fields[] = new HTMLEditorField('Content', 'Content');
	$fields[] = new UploadField('EventImage','Image');

	return new FieldList($fields);
}