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

How to permanently customise jquery.ui.datepicker


Go to End


6 Posts   1160 Views

Avatar
tazzydemon

Community Member, 135 Posts

13 November 2013 at 9:05am

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

Avatar
Devlin

Community Member, 344 Posts

13 November 2013 at 10:16pm

Edited: 13/11/2013 10:24pm

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');

Avatar
tazzydemon

Community Member, 135 Posts

18 November 2013 at 12:07pm

Edited: 18/11/2013 12:14pm

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

Avatar
tazzydemon

Community Member, 135 Posts

18 November 2013 at 1:52pm

Edited: 18/11/2013 1:54pm

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

Avatar
Devlin

Community Member, 344 Posts

18 November 2013 at 10:09pm

Edited: 19/11/2013 9:20am

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');

Avatar
tazzydemon

Community Member, 135 Posts

22 November 2013 at 11:42am

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