Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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 the webform_scheduler as that has the date popup dialog already installed. More details from the module's project page:

It adds an optional start date and end date field to the webform form settings. If the current date and time falls outside the specified window, the webform is disabled.

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.