Note: this FAQ will not work with the standard DatePicker element in the ChronoForms v4 elements list because it is not possible (so far as I know) to identify the datapicker object that is created.
<?php
$document =& JFactory::getDocument();
// make sure that MooTools is loaded
JHTML::_( 'behavior.mootools' );
$cf_url = JURI::root().'components/com_chronoforms/js/datepicker_moo/';
// you can change the uncommented line here to change the style
$datepicker_style = $form->form_params->get( 'datepicker_moo_style', 'datepicker_dashboard' );
$document->addStyleSheet( $cf_url.$datepicker_style.'/'.$datepicker_style.'.css' );
// set the datepicker language
$lang =& JFactory::getLanguage();
$tag = $lang->getTag();
if ( !$tag ) {
$tag = $lang->getDefault();
}
$use_tag = 'en-US';
if ( file_exists( $cf_url.'Locale.'.$tag.'.DatePicker.js' ) ) {
$use_tag = $this->tag;
}
// load the datepicker script files
$document->addScript( $cf_url.'Locale.'.$use_tag.'.DatePicker.js' );
$document->addScript( $cf_url.'Picker.js' );
$document->addScript( $cf_url.'Picker.Attach.js' );
$document->addScript( $cf_url.'Picker.Date.js' );
?>
If you have a another standard Datetime picker element on the page, or are using the Custom MooTools Datepicker action this may not be needed.
var datepicker_a, dp_thumbnail_a;
window.addEvent('domready', function() {
var dp;
dp = $('datepicker_a');
// set up the start datepicker
datepicker_a = new Picker.Date(dp, {
pickerClass: 'datepicker_dashboard',
format: '%Y-%m-%d',
allowEmpty: true,
useFadeInOut: !Browser.ie
});
// add a new image element
dp_thumbnail_a = new Element('img', {
src: '/images/calendar.gif',
styles: {
paddingLeft: '6px'
}
});
// insert the image after the text input
dp_thumbnail_a.inject(dp, 'after');
// link the datepicker to the image
datepicker_a.attach(dp_thumbnail_a);
});
You can find a wide range of calendar icons with a Google Search, please check that you have the necessary permissions to use the icon you choose.
You will also need a Show HTML action in the On Load event to display the form HTML.
Variations
Text link
// add a new image element
dp_thumbnail_a = new Element('span', {
text: 'select a date',
styles: {
paddingLeft: '6px',
color: 'blue',
textDecoration: 'underline'
}
});
Hidden input
Display re-formatted date
var datepicker_a, dp_thumbnail_a;
window.addEvent('domready', function() {
var dp;
dp = $('datepicker_a');
dp.setProperty('type', 'hidden');
// set up the start datepicker
datepicker_a = new Picker.Date(dp, {
pickerClass: 'datepicker_dashboard',
format: '%Y-%m-%d',
allowEmpty: true,
useFadeInOut: !Browser.ie,
onSelect: function(date){
dp_confirm_a.set('text', date.format('%d %b %Y'));
}
});
// add a new image element
dp_thumbnail_a = new Element('img', {
src: '/images/calendar.gif',
styles: {
paddingLeft: '6px'
}
});
// add a new span element
dp_confirm_a = new Element('span', {
text: '',
styles: {
paddingLeft: '6px'
}
});
// insert the icon and span after the text input
dp_confirm_a.inject(dp, 'after');
dp_thumbnail_a.inject(dp, 'after');
// link the datepicker to the image
datepicker_a.attach(dp_thumbnail_a);
});

Comments: