How to get two drop downs to a single field in drupal? -
how 2 drop downs single field? example, time field 1 drop down hours(0-23) , other minutes(0-59).
if have custom module you're using on drupal 7 site, can include implementation of hook_form_alter
makes transformation you. (see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_form_alter/7 detailed explanation of hook.)
basically, want hook form you're trying alter (perhaps testing $form_id
in if
clause make sure matches form want alter) , create 2 new fields hours , minutes, while hiding built-in field shows time you're trying store. here's example:
function mymodule_form_alter(&$form, &$form_state, $form_id) { if ($form_id == 'my_form_id') { $form['original_time_field']['#type'] = 'hidden'; $hours = array(); ($digit = 0; $digit < 24; $digit++) { $hours[$digit] = $digit; } $minutes = array(); ($digit = 0; $digit < 60; $digit++) { $minutes[$digit] = $digit; } $form['hours'] = array( '#type' = 'select', '#options' = $hours, '#title' = t('hours'), ); $form['minutes'] = array( '#type' = 'select', '#options' = $minutes, '#title' = t('minutes'), ); } }
then have couple choices. can either include custom .js
file listens changes hours , minutes pulldowns , rewrites hidden time field value on fly, or can write custom submit handler form in question (using either form api or implementing appropriate hook_form_submit
function) uses $form_state
variable combine 2 virtual fields , write resulting value real time field.
Comments
Post a Comment