I've placed a date field in my form

$fields['Preferred Date'] = array(
'#type' => 'date',
'#title' => t('Preferred Date of Program'),
//'#default_value' => ,
'#description' => t(''),
'#required' => TRUE
);

and it produces the three fields YY MM DD (though I liked to change their order to MM DD YY). How would I put a popup calendar beside this field and have the field change based on the calendar day chosen?

Comments

narayanis’s picture

I believe you just set '#type' => 'date_popup'

mtpultz’s picture

Sweet thanks, I'm looking at the API now http://drupalcontrib.org/api/drupal/contributions--date--date_popup--dat... if I'm creating the date_popup how do I set the format using these functions? Just noticed you can get the time in there too but would like to change how it so the time is a drop down HH : MM instead of a textbox.

I'd also like it as select lists if possible instead of a text input, if that's possible.

Thanks again for the response, that's great

narayanis’s picture

I'm not sure about time, as I haven't worked with that extensively. Here's an example call using the API though:

$form['a_date_filter'] = array(
'#weight' => '3',
'#type' => 'date_popup',
'#title' => 'This is a date filter',
'#date_format' => 'Y-m-d',
'#date_year_range' => '-5:+5', //allow 5 years past and future
'#default_value' => date(Y) . '-01-01', //default date to January 1 of current year
);
mtpultz’s picture

Thanks, that's great.

I was browsing through the Date/Calendar Docs and found that the date widget can be a select field. Is there another property to set that chooses what type of form input should be used.

Just incase it was this easy I tried using '#input' => 'select' and that didn't work. Seemed logical to try that though.

Thanks again

mtpultz’s picture

Never mind, I found out how to get selects from the docs http://drupal.org/node/292667. Thanks so much for the help. Appreciate it :)

mtpultz’s picture

Sorry, one more question. The last thing I need to do now that the field is in place is let the user know it is a date_popup field. Is there a property to show an icon to the right of the field like Wufoo forms does or how might you go about adding a clickable icon that would just open the date_popup for the associated field? Only thing I can see is add it to #suffix with some inlined script and css but that's pretty crude.

narayanis’s picture

What about using the suffix to put in just the icon, and changing the CSS in your main file to have padding on the right-hand side that covers the area of the text field plus the icon?