Jump to:

23363 Posts in 18124 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » 3.1.3 DateField - Blonde Moment

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: 351 Views
  • heinvd
    Avatar
    Community Member
    5 Posts

    3.1.3 DateField - Blonde Moment Link to this post

    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...

  • thomas.paulson
    Avatar
    Community Member
    67 Posts

    Re: 3.1.3 DateField - Blonde Moment Link to this post

       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;
       }

  • heinvd
    Avatar
    Community Member
    5 Posts

    Re: 3.1.3 DateField - Blonde Moment Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5486 Posts

    Re: 3.1.3 DateField - Blonde Moment Link to this post

    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

    351 Views
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.