Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » How to permanently customise jquery.ui.datepicker

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: 451 Views
  • tazzydemon
    Avatar
    Community Member
    120 Posts

    How to permanently customise jquery.ui.datepicker Link to this post

    My site currently used a custom version of framework/thirdparty/jquery-ui/datepicker/i18n/jquery.ui.datepicker-en-GB.js so that I can have year selection and a default start date.

    All very well but a git pull or framework file update will destroy it.

    Id there a default place I can put a copy so it will be found or is there a way I can tell the framework to look somewhere else

    Julian

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: How to permanently customise jquery.ui.datepicker Link to this post

    You need to overload DateField_View_JQuery and add your javascript file to the requirements.

    class myDateField_View_JQuery extends DateField_View_JQuery {
       
       /**
        * @param String $html
        * @return
        */
       public function onAfterRender($html) {
          $html = parent::onAfterRender($html);
          
          Requirements::javascript('mydatefield.js');
          
          return $html;
       }
       
    }

    Object::useCustomClass('DateField_View_JQuery', 'myDateField_View_JQuery');

  • tazzydemon
    Avatar
    Community Member
    120 Posts

    Re: How to permanently customise jquery.ui.datepicker Link to this post

    Thanks a lot. I would have had no idea where to look for this.

    Now I see its in framework/forms/DateField.php and I observe that at the moment there are no other form elements that have the same treatment - however calendar is very particular about its use and may indeed vary on one site.

    Julian

  • tazzydemon
    Avatar
    Community Member
    120 Posts

    Re: How to permanently customise jquery.ui.datepicker Link to this post

    There seems to be a snag.

    DateField_View_JQuery is only used for static method calls that I can tell, which means I can't useCustomClass() on it as it's never created with the factory method Object::create().

    So its back to the drawing board. ..

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: How to permanently customise jquery.ui.datepicker Link to this post

    it's never created with the factory method Object::create().

    Of course it is. It's in DateField::FieldHolder()... Line 118... Works fine for me.

    if ($this->getConfig('showcalendar')) {
       // TODO Replace with properly extensible view helper system
       $d = DateField_View_JQuery::create($this);

    ~~

    may indeed vary on one site

    Well, then you need to overload DateField() itself and add your code as required.

    class MyDateField extends DateField{
       function FieldHolder($properties = array()) {
          $html = parent::FieldHolder($properties);
          Requirements::javascript('mydatefield.js');
          return $html;
       }
    }
    $myDateField = MyDateField::create('date');
    // or
    $myDateField = new MyDateField('date');

  • tazzydemon
    Avatar
    Community Member
    120 Posts

    Re: How to permanently customise jquery.ui.datepicker Link to this post

    I'll have another look. I did a searc for that and did not find it.

    I realise I could have extended and customised it in where it was finally called but I wanted to override the Class in such a way as when the repos are refreshed that change does not get erased anywhere including userdefined forms module

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