[TYPO3-dev] BE Module: How to add a datepicker to an input

François Suter fsu-lists at cobweb.ch
Thu Nov 17 15:43:08 CET 2011


Hi Stephen,

> When creating fields in a BE module (for user submission, not for any
> particular table record), how can I create a datepicker like the record
> forms have?

Here's some code from the Scheduler's BE module, which doesn't use TCEforms:

	// Start date/time field
	// NOTE: datetime fields need a special id naming scheme
$label = '<label for="tceforms-datetimefield-task_start">' . 
$GLOBALS['LANG']->getLL('label.start') . '</label>';
$table[$tr][] = t3lib_BEfunc::wrapInHelp($this->cshKey, 'task_start', 
$label);
$table[$tr][] = '<input name="tx_scheduler[start]" type="text" 
id="tceforms-datetimefield-task_start" value="' . 
((empty($taskInfo['start'])) ? '' : strftime('%H:%M %d-%m-%Y', 
$taskInfo['start'])) . '" />' .
	t3lib_iconWorks::getSpriteIcon(
		'actions-edit-pick-date',
		array(
			'style' => 'cursor:pointer;',
			'id' => 'picker-tceforms-datetimefield-task_start'
		)
	);

The important part is the naming of the "id" attribute. You also need to 
include some JavaScript libraries:

$pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/tceforms.js');
$pageRenderer->addJsFile($this->backPath . 
'../t3lib/js/extjs/ux/Ext.ux.DateTimePicker.js');

I think this should do.

HTH

-- 

Francois Suter
Cobweb Development Sarl - http://www.cobweb.ch



More information about the TYPO3-dev mailing list