It'd be handy to have a date component type that only requires entering month and year, or an option on the date component that lets you just use month and year.

I worked up a cheezy fix by removing the lines below from the _webform_render_date function, near the end. These are the 6 lines commented out below:

  $formItem['month'] = array(
    '#type' => 'select',
    '#default_value' => $month,
    '#options' => $months,
    '#validate' => array ('webform_validate_date' => array ('month',$component['name'],$component['mandatory']) ),
    );
// $formItem['day'] = array(
//    '#type' => 'select',
//    '#default_value' => $day,
//    '#options' => $days,
//    '#validate' => array ('webform_validate_date' => array ('day',$component['name'],$component['mandatory']) ),
//    );
  $formItem['year'] = array(
    '#type' => 'textfield',
    '#default_value' => $year,
    '#maxlength' => 4,
    '#size' => 4,
    '#validate' => array ('webform_validate_date' => array ('year',$component['name'],$component['mandatory']) ),
    );

This simply removes the day part of the date from the input form -- and there's probably a much better way to adapt this component. It appears to work fine as a substitute for the date component; my guess is that if you wanted to use both this and the shipped date component, you'd need to change the function names to avoid conflicts.

Comments

BioALIEN’s picture

Thanks for the info. I think the proper way to do this would be to show all the options:
Year Month Day Hour Minute Second

And let the user filter what type to show or how many levels - exactly how the CCK module folks have done.

dquakenbush’s picture

Did this go anywhere?

dquakenbush’s picture

Here's a fix that puts a checkbox in the form assembly screen...
I couldn't get it to work without any day (would drop the date entirely on the e-mail), so the check box hides the day field and forces the day to "01", which shows up in the e-mail... works for what we're doing, and hopefully will help you until a proper patch can be created by a real programmer...

All changes are in date.inc

Near line 38 I added this just before the "return $edit_fields;" :

$edit_fields['extra']['ignore_day'] = array(
    '#type' => 'checkbox',
    '#title' => t("Hide Day Field"),
    '#default_value' => $currfield['extra']['ignore_day'],
    '#checked_value' => 1,
    '#description' => t('Hide the day field -- only show month and year.'),
    '#weight' => 2,
  );

Then in the render area I replaced the [day] code with this:


  // What do we show if the day is supressed?  Fiddle day field type between select or hidden.
    if ($component['extra']['ignore_day']=='1') {
    	//no day
    	$form_item['day'] = array(
		'#type' => 'hidden', 
		'#value' => '01',
		);
    	
    }else{
    	//day
		$form_item['day'] = array(
		'#type' => 'select', 
		'#default_value' => $day,
		'#options' => $days,
		'#validate' => array('webform_validate_date' => array('day', $component['name'], $component['form_key'], $component['mandatory'])),
		);    	
    	
    }

No guarantees this won't break something somewhere, but it seems to work for me. Good luck :-)

quicksketch’s picture

Status: Needs work » Closed (won't fix)

If this functionality is ever added to webform it'll come as an enhancement to the existing date component. In Drupal 6, we may be able to reuse the date.module configuration (which is quite extensive). Let's open a new issue for this functionality as a part of the date component if desired.