Just a vague pondering which I don't have time to work on... ;)

Currently this only works on CCK date fields. But the changes we make to the date field are actually made to the date form element -- adding a #theme and an #after_build callback.

It might be possible to do this to any date form element, using the same technique as in http://drupal.org/project/checkbox_validate -- that redeclares (I think!) the checkboxes element to have a different #process callback.

If this were possible, then our own #process callback would check for a custom key, say, #single_day, and act on that.

Meanwhile, the CCK side of things in date_single_day_form_alter() would just set #single_day for the processing to find.

The upshot would be that nothing changes... ;) but a custom module that uses a date element in its own form could also request it to have a single day by setting #single_day in the form array.

Comments

damienmckenna’s picture

Status: Active » Closed (duplicate)
damienmckenna’s picture

Status: Closed (duplicate) » Active

Wait, no, that's not strictly a duplicate. #facepalm

joachim’s picture

Status: Active » Needs review
StatusFileSize
new2.87 KB

I've got this working but I'm not convinced.

It adds a fair amount of code, and I'm not sure there's much gain. The only Form API element where this makes sense is date_combo, which is defined in CCK Date module anyway.

Here's the patch while I ponder it.

anjjriit’s picture

How to theme my date form element ?
i have tried //'#theme' => array('date_single_day_element'), ---> but did not worked

function my_module_form_alter(){
	$form['date'] = array(
	  '#prefix'=>t('When do you want to start your date ?'),
	  '#date_format' => 'Y-m-d H:i',
	  '#date_year_range' => '0:+1',
	  '#type' => 'date_popup',
	  '#required'=>TRUE,
	  '#weight'=>-10,
	  '#datepicker_options' => array('minDate' => 0),
	  //'#theme' => array('date_single_day_element'), ---> its did not worked
	);
	$form['date2'] = array(
	  '#prefix'=>t('When do you will be finished your date ?'),
	  '#date_format' => 'Y-m-d H:i',
	  '#date_year_range' => '0:+1',
	  '#type' => 'date_popup',
	  '#required'=>TRUE,
	  '#weight'=>-9,
	  '#datepicker_options' => array('minDate' => 0),
	  //'#theme' => array('date_single_day_element'), ---> its did not worked
	);
return $form;
}

Thanks