Hi,
This post is about fixes for the date-picker bugs in ChronoForms v4RC1.8. These fixes were developed in Joomla! 1.5 and have not yet been tested in Joomla! 1.6 so some small tweaks may still be required.
The default date-picker works OK but problems arise when you try to customise a date or time picker. Please see points e, f & g in the previous post.
There are two changes required for this fix. The first is in administrator/components/com_chronoforms/helpers/html_helper.php around line 287. Look for the section starting
case 'datetime': and replace the first part as show here:
case 'datetime':
// start hack
if ( $tag['class'] ) {
str_replace(array(' ', ' ', ' '), ' ', $tag['class']);
$class_array = explode (' ', $tag['class']);
} else {
$class_array = array();
}
if ( isset($tag['timeonly']) && (int)$tag['timeonly'] == 1 ) {
$class_array[] = 'cf_time_picker';
} elseif ( isset($tag['addtime']) && (int)$tag['addtime'] == 1 ) {
$class_array[] = 'cf_datetime_picker';
} else {
$class_array[] = 'cf_date_picker';
}
$tag['class'] = implode(' ', $class_array);
// end hack
if(isset($tag['timeonly']))unset($tag['timeonly']);
if(isset($tag['addtime']))unset($tag['addtime']);
unset($tag['tag']);
$tag['type'] = 'text';
$output .= '<input';
foreach($tag as $k => $v) {
$output .= ' '.$k.'="'.$v.'"';
}
$output .= ' />'."\n";
break;
This fix cleans up the adding of classes to the datepicker.
The second fix is to the file administrator/components/com_chronoforms/form_actions/show_html/cfaction_show_html.php around line 189. Look for the
function _loadDatePickerScripts($form) and replace the whole function with
function _loadDatePickerScripts($form)
{
$document =& JFactory::getDocument();
JHTML::_('behavior.mootools');
global $mainframe;
$CF_PATH = ($mainframe->isSite()) ? JURI::Base() : $mainframe->getSiteURL();
$document->addStyleSheet($CF_PATH.'components/com_chronoforms/css/datepicker/datepicker_dashboard.css');
$document->addScript($CF_PATH.'components/com_chronoforms/js/datepicker/datepicker.js');
$datetime_array = array(
"cf_date_picker" => "{pickerClass: 'datepicker_dashboard', inputOutputFormat: 'Y-m-d H:i:s', allowEmpty: true}",
"cf_datetime_picker" => "{pickerClass: 'datepicker_dashboard', inputOutputFormat: 'Y-m-d H:i:s', timePicker: true, allowEmpty: true}",
"cf_time_picker" => "{pickerClass: 'datepicker_dashboard', inputOutputFormat: 'Y-m-d H:i:s', timePickerOnly: true, allowEmpty: true}"
);
//$selector = 'dateTimePicker';
$settings = array();
$datetime_picker_selectors = $form->form_params->get('datepicker_config', '');
if ( !empty($datetime_picker_selectors) ) {
$date_selectors = explode("|#|", $datetime_picker_selectors);
foreach ( $date_selectors as $date_selector ) {
if ( !$date_selector ) {
continue;
}
$config = explode("::", $date_selector);
$selector = trim($config[0]);
$datePickerSettings = "{pickerClass: 'datepicker_dashboard', inputOutputFormat: 'Y-m-d H:i:s', allowEmpty: true}";
if ( trim($config[1]) ) {
$config[1] = trim($config[1]);
$config[1] = substr($config[1], 0, strrpos($config[1], '}'));
$temp = array($config[1]);
//add the picker class if not set by the user
if ( strpos($config[1], "pickerClass" ) === false){
$temp[] = "pickerClass: 'datepicker_dashboard'";
}
//add the value format if not set by the user
if ( strpos($config[1], "inputOutputFormat" ) === false ){
$temp[] ="inputOutputFormat: 'Y-m-d H:i:s'";
}
//add the allowEmpty format if not set by the user
if ( strpos($config[1], "allowEmpty" ) === false ){
$temp[] ="allowEmpty: true";
}
$datePickerSettings = implode(', ', $temp).' }';
}
$settings[$selector] = $datePickerSettings;
unset($config, $temp);
}
}
$settings = array_merge($settings, $datetime_array);
$script = "";
foreach($settings as $class => $setting) {
$script .= "new DatePicker( '.{$class}', {$setting} ); \n";
$script .= "console.log(startDate); \n";
}
$script = "//<![CDATA[
window.addEvent('load', function() {
{$script}
});
//]]>
";
$document->addScriptDeclaration($script);
}
This fix cleans up the addition of default options to the datepicker; sets any custom datepicker class before the standard classes; and fixes the bug with options containing a }.
Later . . .
Please see
this post for a fix to the second code chunk above for Joomla! 1.6.
BUT it looks as though this version of datepicker.js won't run under Mootools 1.3 (used in Joomla! 1.6.3+) There's an forked version linked from the post with the fix - not yet trialled.
Bob