Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I am using webforms in Drupal 7. Is there a way to set the date field to a single textfield instead of 3 select fields?

share|improve this question

2 Answers 2

Since it seems like the webfrom module doesn't support this functionality yet, if found that the easiest way to do this, was to use a textfield and use form_alter to add the datepicker plugin.

function custom_form_form_alter(&$form, &$form_state, $form_id) {

  if($form_id != 'webform_client_form_2') return;

  // Alter textfield for date to integrate popup calendar
  $form["submitted"]["expected_move_date"] = array(
    '#type' => 'item',
    'finished_after' => array(
      '#type' => 'textfield',
      '#attributes' => array('class' => array('datepicker')),
      '#required' => TRUE,

  $form['#after_build'] = array('custom_form_uidatepicker');


function custom_form_uidatepicker($form, $form_state) {
  drupal_add_library('system', 'ui.datepicker');
  drupal_add_js("(function ($) { $('.datepicker').datepicker({
      showOn: 'both',
      buttonImage: 'sites/all/modules/custom/custom_form/images/calendar.png',
      buttonImageOnly: true,
      dateFormat: 'dd/mm/yy',
    $('.datepicker').datepicker( 'option', 'minDate', 'd' );
    })(jQuery);", array('type' => 'inline', 'scope' => 'footer', 'weight' => 5));

    return $form;
share|improve this answer
How would you use the code above? Paste it in the theme template.php? I notice there is a path to sites/all/modules/custom/custom_form/images/calendar.png does this mean you created a custom module.. very unclear... –  user23723 Nov 15 '13 at 14:04
Yes Paul. I have created a custom module. –  Eytyy Nov 16 '13 at 14:19

It might be best to use this: http://drupal.org/project/webform_scheduler as that has the date popup dialog already installed.

share|improve this answer
That module does something completely different. –  inta May 15 '13 at 10:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.