Solution.
Note: this has been amended from the original forum post to simplify it a little and to use the Joomla! methods to load the JQuery files rather than amending the template.
NB! For this to work at the same time with Chronoforms built-in Mootools validation, you must be able to make jQuery and Mootools live on the same page without conflicts. How to do that is outside the scope of this guide.
<div id="datepicker"></div>
<input type='hidden' name='calendar_date' id='calendar_date' value='' />
<?php // set a default date for the calendar if ( !isset($form->data['calendar_date']) || !$form->data['calendar_date'] ) { $form->data['calendar_date'] = date('m/d/Y'); } ?>
<?php // load jQuery scripts // loaded from Joomla! 3 JHtml::_('jquery.framework'); JHtml::_('jquery.ui'); $doc =& JFactory::getDocument(); // loaded from the code.jquery.com site $doc->addStylesheet('http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css'); // loaded from a copy in a local folder$doc->addScript(JURI::root().'/components/com_chronoforms/extras/jquery/jquery.ui.datepicker.js'); ?>
You will need to check that the appropriate files are being loaded on your site!!
Here I am using Joomla! 3 which has some of the core jQuery files included by default. See the comments in the code for the different methods used. Which is best will depend on your site version and setup.
Note: the jQuery datepicker is not included in the default Joomla jQuery files so I downloaded it from the jQuery site and added a copy of the file and the related language files to the /components/com_chronoforms/extras/jquery/ folder on my site.
5. The second block sets up the datepicker:
jQuery(function() { jQuery('#datepicker').datepicker( { minDate: -1, prevText: '', nextText: '', maxDate: '+3M', firstDay: 1, dateFormat: 'mm/dd/yy', onSelect: function(dateText, inst) { jQuery('#calendar_date').val(dateText); } }); });
prevText: "" and nextText: "" - changes Previous and Next text to empty, useful if you wish to insert some image there instead of words
maxDate: "+3M" - shows only 3 months in the future
firstDay: 1 - makes Monday the first day of the week
dateFormat: "mm/dd/yy" - defines date format (note that this is a JavaScript format string while the earlier one was a PHP format string)
onSelect - this part adds selected date as a value to the hidden field we made previously.
jQuery('#datepicker').datepicker( jQuery.datepicker.regional['de'] );
/* German initialisation for the jQuery UI date picker plugin. */ /* Written by Milian Wolff (mail@milianw.de). */ jQuery(function($){ $.datepicker.regional['de'] = { closeText: 'schließen', prevText: '<zurück', nextText: 'Vor>', currentText: 'heute', monthNames: ['Januar','Februar','März','April','Mai','Juni', 'Juli','August','September','Oktober','November','Dezember'], monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun', 'Jul','Aug','Sep','Okt','Nov','Dez'], dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'], dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'], dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'], weekHeader: 'KW', dateFormat: 'dd.mm.yy', firstDay: 1, isRTL: false, showMonthAfterYear: false, yearSuffix: ''}; $.datepicker.setDefaults($.datepicker.regional['de']); }); jQuery(function() { jQuery( "#datepicker" ).datepicker({ minDate: -1, prevText: "", nextText: "", maxDate: "+3M", firstDay: 1, dateFormat: "dd.mm.yy", onSelect: function(dateText, inst) { jQuery("#submittedDate").val(dateText); } } ); jQuery( "#datepicker" ).datepicker( jQuery.datepicker.regional[ "de" ] ); });