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

3.1.3 DateField - Blonde Moment


Go to End


4 Posts   970 Views

Avatar
heinvd

Community Member, 5 Posts

14 March 2014 at 1:47am

Hi there,

I have an issue setting the datefield to have three seperate dropdowns. I googled and tried a few alternatives... but with no luck...

here is my code snipped....

function getCMSFields()
{
$fields = parent::getCMSFields();
$dateField = new DateField('DateOfBirth');
$dateField->setConfig('dmyfields',true);
$fields->replaceField('DateOfBirth',$dateField);
return $fields;
}

Please slap me if I done something stupid.... also remember, I am a SS noob...

Avatar
thomas.paulson

Community Member, 107 Posts

14 March 2014 at 10:59pm

public function getCMSFields()
{
$fields = parent::getCMSFields();
$dateField = new DateField('DateOfBirth');
$dateField->setConfig('dmyfields',true);
$fields->addFieldToTab('Root.Main', $dateField, 'Content');
//$fields->replaceField('DateOfBirth',$dateField);
return $fields;
}

Avatar
heinvd

Community Member, 5 Posts

15 March 2014 at 12:45am

Hi Thomas, thanks for your reply.

I'm going to give more detail, because I dont know if what I am doing is really going to work.

I am extending members using a dataextension.

class MyMember extends DataExtension {

static $db = array
(
'DateOfBirth'=>'Date'
);

static $has_one = array
(
'MemberAvatar' => 'Image'
);

public function getCMSFields()
{
$fields = parent::getCMSFields();
$dateField = new DateField('DateOfBirth');
$dateField->setConfig('dmyfields',true);
$fields->addFieldToTab('Root.Main', $dateField, 'Content'); //added by thomas
//$fields->replaceField('DateOfBirth',$dateField); //removed by thomas
return $fields;
}

}

i then have the extension added in the yaml file:

Member:
extensions:
- MyMember

Avatar
Willr

Forum Moderator, 5523 Posts

23 March 2014 at 6:28pm

In an extension the method call is updateCMSFields(FieldList $list), not getCMSFields.

Also FYI dmyfields will give you three inputs not 3 dropdowns. If you want to have dropdowns have a look at https://github.com/dnadesign/silverstripe-datedropdownselectorfield