Index: select.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/select.inc,v retrieving revision 1.22.2.29 diff -u -r1.22.2.29 select.inc --- select.inc 4 Mar 2009 05:05:11 -0000 1.22.2.29 +++ select.inc 5 Oct 2009 10:13:02 -0000 @@ -22,6 +22,7 @@ 'items' => '', 'email' => 0, 'multiple' => NULL, + 'select_or_other' => NULL, 'aslist' => NULL, 'description' => '', ), @@ -66,6 +67,13 @@ '#default_value' => $currfield['extra']['multiple'], '#description' => t('Check this option if the user should be allowed to choose multiple values.'), ); + $edit_fields['extra']['select_or_other'] = array( + '#type' => 'checkbox', + '#title' => t('Allow Other option'), + '#return_value' => 'Y', + '#default_value' => $currfield['extra']['select_or_other'], + '#description' => t('Check this option if you want to allow users to enter an option not on the list.'), + ); $edit_fields['extra']['aslist'] = array( '#type' => 'checkbox', '#title' => t('Listbox'), @@ -171,26 +179,44 @@ $form_item['#default_value'] = $default_value; } } + elseif ($component['extra']['multiple'] === 'Y') { + $form_item['#default_value'] = array(); + } - if ($component['extra']['aslist'] === 'Y') { + if ($component['extra']['select_or_other'] === 'Y') { // Set display as a select list: - $form_item['#type'] = 'select'; + $form_item['#type'] = 'select_or_other'; + $form_item['#other'] = t('Other (specify)'); + $form_item['#other_unknown_defaults'] = 'other'; + $form_item['#other_delimiter'] = ', '; if ($component['extra']['multiple'] === 'Y') { $form_item['#multiple'] = TRUE; + $form_item['#select_type'] = 'checkboxes'; + } else { + $form_item['#multiple'] = FALSE; + $form_item['#select_type'] = 'radios'; + } + if ($component['extra']['aslist'] === 'Y') { + $form_item['#select_type'] = 'select'; } } - else { + elseif ($component['extra']['aslist'] === 'Y') { + // Set display as a select list: + $form_item['#type'] = 'select'; if ($component['extra']['multiple'] === 'Y') { - // Set display as a checkbox set. - $form_item['#type'] = 'checkboxes'; - // Drupal 6 hack to properly render on multipage forms. - $form_item['#process'] = array('webform_expand_checkboxes'); - } - else { - // Set display as a radio set. - $form_item['#type'] = 'radios'; + $form_item['#multiple'] = TRUE; } } + elseif ($component['extra']['multiple'] === 'Y') { + // Set display as a checkbox set. + $form_item['#type'] = 'checkboxes'; + // Drupal 6 hack to properly render on multipage forms. + $form_item['#process'] = array('webform_expand_checkboxes'); + } + else { + // Set display as a radio set. + $form_item['#type'] = 'radios'; + } return $form_item; } @@ -264,15 +290,17 @@ */ function _webform_submit_select(&$data, $component) { $options = drupal_map_assoc(array_flip(_webform_select_options($component['extra']['items'], TRUE))); - + if (is_array($data)) { foreach ($data as $key => $value) { if ($value != '') { - $data[$key] = $options[$key]; - } - // Checkboxes submit a value of 0 when not checked. - elseif ($value == 0 && $component['extra']['aslist'] !== 'Y' && $component['extra']['multiple'] === 'Y') { - unset($data[$key]); + if (is_null($options[$key]) && $component['extra']['select_or_other'] === 'Y') + { + $data[$key] = $data[$key]; + } + else { + $data[$key] = $options[$key]; + } } else { unset($data[$key]);