@idefix.
Try this
$dateField = new DateField('Date');
$dateField->setConfig('showcalendar', true);
$dateField->setValue('PRESET_VALUE_IN_HERE');
$fields->addFieldToTab("Root.Content.Main", $dateField);
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba
@idefix.
Try this
$dateField = new DateField('Date');
$dateField->setConfig('showcalendar', true);
$dateField->setValue('PRESET_VALUE_IN_HERE');
$fields->addFieldToTab("Root.Content.Main", $dateField);
@Blackdog
Thanks for the hint.
The preset value appears, but not the calendar!
But I want both.
Have you tried the following?
new DateField('Date','Date','PRESET IN HERE');
Sorry, Calendar is now here, but no more the preset value!
Hi Blackdog,
This:
$ende = new DateField('Ende','Ende', '31/10/2010');
$ende->setConfig('showcalendar', true);
$fields->addFieldToTab("Root.News", $ende);
is the same as before, Calendar yes, Preset value is not visible and not even preselected in the calendar.
Is there any special way to format the date?
Hi,
I solved my problem:
to prefill a datefield you have to set the DataObject-variable.
e.g.:
function getCMSFields() {
$fields = parent::getCMSFields();
$today = date("d/m/Y");
$fldCalendar = new DatePickerField("Start","Start-Datum",$value="$today"); // $value="$today" doesn't take effect but in TextField it DOES!
if (!$this->Start) $this->Start = $heute; // THIS is the important thing! to show in the new created DataObject Form a prefilling value
$fields->addFieldToTab("Root.Content", $fldCalendar);
return $fields;
}
Maybe somebody can save some time with this.