--- webform-6.x-2.7/components/select.inc 2009-03-04 00:05:11.000000000 -0500 +++ webform-devel/components/select.inc 2009-07-16 14:29:52.000000000 -0400 @@ -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. A listbox will be used instead of radiobuttons or checkboxes, regardless of the setting below.'), + ); $edit_fields['extra']['aslist'] = array( '#type' => 'checkbox', '#title' => t('Listbox'), @@ -149,9 +157,9 @@ // Convert the user-entered options list into an array. $default_value = _webform_filter_values($component['value'], NULL, NULL, FALSE); - $options = _webform_select_options($component['extra']['items'], $component['extra']['aslist'] !== 'Y'); + $options = _webform_select_options($component['extra']['items'], $component['extra']['select_or_other'] !== 'Y' && $component['extra']['aslist'] !== 'Y'); - if ($component['extra']['aslist'] === 'Y' && $component['extra']['multiple'] !== 'Y') { + if (($component['extra']['select_or_other'] === 'Y' || $component['extra']['aslist'] === 'Y') && $component['extra']['multiple'] !== 'Y') { $options = array('' => t('select...')) + $options; } @@ -172,25 +180,33 @@ } } - 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'] = 'Other (specify)'; + $form_item['#other_unknown_defaults'] = 'other'; + $form_item['#other_delimiter'] = ', '; if ($component['extra']['multiple'] === 'Y') { $form_item['#multiple'] = TRUE; } } - 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; } @@ -271,7 +287,7 @@ $data[$key] = $options[$key]; } // Checkboxes submit a value of 0 when not checked. - elseif ($value == 0 && $component['extra']['aslist'] !== 'Y' && $component['extra']['multiple'] === 'Y') { + elseif ($value == 0 && $component['extra']['select_or_other'] !== 'Y' && $component['extra']['aslist'] !== 'Y' && $component['extra']['multiple'] === 'Y') { unset($data[$key]); } else {