Jump to:

22977 Posts in 11720 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » DateField in SS 2.4.1

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: 1959 Views
  • borriej
    Avatar
    Community Member
    267 Posts

    DateField in SS 2.4.1 Link to this post

    Hello,

    It used to be so easy in SS 2.3.7. Now it's not working in SS 2.4.1

    Problem:
    When entering a date in the CMS, like 08/16/2010

    It is - after save - converted to: Aug 16, 2010

    But when you edit the page, and click save again you get the error:
    'validation failed'

    This is because the date is as text, because when i enter the date in numbers again, it will save.

    How do i fix this/ Keep the date in numbers??

    Thanks!

    the code: http://paste2.org/p/953549

  • Zauberfisch
    Avatar
    Community Member
    30 Posts

    Re: DateField in SS 2.4.1 Link to this post

  • borriej
    Avatar
    Community Member
    267 Posts

    Re: DateField in SS 2.4.1 Link to this post

    Working!
    Complete code

    <?php
    /**
    * Defines the ArticlePage page type
    */
    class ArticlePageextends Page {
    static $db = array(
    'Date' => 'Date',
    'Author' => 'Text'
    );

    static $has_one = array(
    );

       function getCMSFields() {
          $fields = parent::getCMSFields();
          
          $DateField = new Datefield('Date','Date');
          $DateField->setConfig('showcalendar', true);
          $DateField->setConfig('dateformat', 'dd-MM-YYYY');

          $fields->addFieldToTab('Root.Content.Main', $DateField, 'Content');   
          $fields->addFieldToTab('Root.Content.Main', new TextField('Author'), 'Content');
          
          return $fields;
       }

    }

    class ArticlePage_Controller extends Page_Controller {

    }

    ?>

  • web2works
    Avatar
    Community Member
    50 Posts

    Re: DateField in SS 2.4.1 Link to this post

    Thank you, this was very helpful

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