Index: webform.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.css,v
retrieving revision 1.12
diff -u -r1.12 webform.css
--- webform.css	10 Feb 2010 05:23:09 -0000	1.12
+++ webform.css	25 Mar 2010 00:46:22 -0000
@@ -44,6 +44,18 @@
 td.webform-pagebreak {
   font-weight: bold;
 }
+.webform-options-element thead {
+  display: none;
+}
+.webform-options-element fieldset {
+  border: none;
+  background: none;
+  margin: 0;
+  padding: 0;
+}
+.webform-options-element fieldset legend {
+  display: none;
+}
 .webform-checkbox {
   text-align: center;
   width: 40px;
Index: components/grid.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/grid.inc,v
retrieving revision 1.19
diff -u -r1.19 grid.inc
--- components/grid.inc	21 Mar 2010 03:38:25 -0000	1.19
+++ components/grid.inc	25 Mar 2010 00:46:22 -0000
@@ -26,6 +26,8 @@
       'optrand' => 0,
       'qrand' => 0,
       'description' => '',
+      'custom_option_keys' => 0,
+      'custom_question_keys' => 0,
     ),
   );
 }
@@ -50,28 +52,71 @@
  */
 function _webform_edit_grid($component) {
   $form = array();
-  $form['extra']['options'] = array(
-    '#type' => 'textarea',
-    '#title' => t('Options'),
-    '#default_value' => $component['extra']['options'],
-    '#description' => t('Options to select across the top. One option per line. Key-value pairs must be entered separated by pipes. i.e. safe_key|Some readable option') . theme('webform_token_help'),
-    '#cols' => 60,
-    '#rows' => 5,
-    '#weight' => -3,
-    '#required' => TRUE,
-    '#element_validate' => array('_webform_edit_validate_select'),
-  );
-  $form['extra']['questions'] = array(
-    '#type' => 'textarea',
-    '#title' => t('Questions'),
-    '#default_value' => $component['extra']['questions'],
-    '#description' => t('Questions list down the left side. One question per line. Key-value pairs must be entered separated by pipes. i.e safe_key|Some readable option') . theme('webform_token_help'),
-    '#cols' => 60,
-    '#rows' => 5,
-    '#weight' => -2,
-    '#required' => TRUE,
-    '#element_validate' => array('_webform_edit_validate_select'),
-  );
+
+  if (module_exists('options_element')) {
+    $form['options'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Options'),
+      '#collapsible' => TRUE,
+      '#description' => t('Options to select across the top. Usually these are ratings such as "poor" through "excellent" or "strongly disagree" through "strongly agree".'),
+      '#attributes' => array('class' => 'webform-options-element'),
+      '#element_validate' => array('_webform_edit_validate_options'),
+    );
+    $form['options']['options'] = array(
+      '#type' => 'options',
+      '#options' => _webform_select_options($component['extra']['options'], TRUE),
+      '#optgroups' => FALSE,
+      '#default_value' => FALSE,
+      '#optgroups' => FALSE,
+      '#key_type' => 'mixed',
+      '#key_type_toggle' => t('Customize option keys (Advanced)'),
+      '#key_type_toggled' => $component['extra']['custom_option_keys'],
+    );
+
+    $form['questions'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Questions'),
+      '#collapsible' => TRUE,
+      '#description' => t('Questions list down the side of the grid.'),
+      '#attributes' => array('class' => 'webform-options-element'),
+      '#element_validate' => array('_webform_edit_validate_options'),
+    );
+    $form['questions']['options'] = array(
+      '#type' => 'options',
+      '#options' => _webform_select_options($component['extra']['questions'], TRUE),
+      '#optgroups' => FALSE,
+      '#default_value' => FALSE,
+      '#optgroups' => FALSE,
+      '#key_type' => 'mixed',
+      '#key_type_toggle' => t('Customize question keys (Advanced)'),
+      '#key_type_toggled' => $component['extra']['custom_question_keys'],
+    );
+  }
+  else {
+    $form['extra']['options'] = array(
+      '#type' => 'textarea',
+      '#title' => t('Options'),
+      '#default_value' => $component['extra']['options'],
+      '#description' => t('Options to select across the top. One option per line. Key-value pairs must be entered separated by pipes. i.e. safe_key|Some readable option') . theme('webform_token_help'),
+      '#cols' => 60,
+      '#rows' => 5,
+      '#weight' => -3,
+      '#required' => TRUE,
+      '#element_validate' => array('_webform_edit_validate_select'),
+    );
+    $form['extra']['questions'] = array(
+      '#type' => 'textarea',
+      '#title' => t('Questions'),
+      '#default_value' => $component['extra']['questions'],
+      '#description' => t('Questions list down the side of the grid. One question per line. Key-value pairs must be entered separated by pipes. i.e safe_key|Some readable option') . theme('webform_token_help'),
+      '#cols' => 60,
+      '#rows' => 5,
+      '#weight' => -2,
+      '#required' => TRUE,
+      '#element_validate' => array('_webform_edit_validate_select'),
+    );
+  }
+
   $form['display']['optrand'] = array(
     '#type' => 'checkbox',
     '#title' => t('Randomize Options'),
Index: components/select.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/select.inc,v
retrieving revision 1.48
diff -u -r1.48 select.inc
--- components/select.inc	21 Mar 2010 04:09:14 -0000	1.48
+++ components/select.inc	25 Mar 2010 00:46:22 -0000
@@ -26,6 +26,7 @@
       'other_option' => NULL,
       'other_text' => t('Other...'),
       'description' => '',
+      'custom_keys' => FALSE,
     ),
   );
 }
@@ -47,51 +48,87 @@
 function _webform_edit_select($component) {
   $form = array();
 
-  $form['extra']['items'] = array(
-    '#type' => 'textarea',
-    '#title' => t('Options'),
-    '#default_value' => $component['extra']['items'],
-    '#description' => t('<strong>Key-value pairs MUST be specified as "safe_key|Some readable option"</strong>. Only alphanumeric characters and underscores are allowed as a key. One option per line. Option groups may be specified with &lt;Group Name&gt;. &lt;&gt; can be used to insert items at the root of the menu after specifying a group.') . theme('webform_token_help'),
-    '#cols' => 60,
-    '#rows' => 5,
-    '#weight' => -2,
-    '#required' => TRUE,
-    '#element_validate' => array('_webform_edit_validate_select'),
-  );
-  $form['value'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Default value'),
-    '#default_value' => $component['value'],
-    '#description' => t('The default value of the field. For multiple selects use commas to separate multiple defaults.') . theme('webform_token_help'),
-    '#size' => 60,
-    '#maxlength' => 256,
-    '#weight' => 0,
-  );
-  $form['extra']['multiple'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Multiple'),
-    '#default_value' => $component['extra']['multiple'],
-    '#description' => t('Check this option if the user should be allowed to choose multiple values.'),
-  );
-  $form['extra']['aslist'] = array(
+  $other = array();
+  if (module_exists('select_or_other')) {
+    $other['other_option'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Allow "Other..." option'),
+      '#default_value' => $component['extra']['other_option'],
+      '#description' => t('Check this option if you want to allow users to enter an option not on the list.'),
+      '#parents' => array('extra', 'other_option'),
+    );
+    $other['other_text'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Text for "Other..." option'),
+      '#default_value' => $component['extra']['other_text'],
+      '#description' => t('If allowing other options, enter text to be used for other-enabling option.'),
+      '#parents' => array('extra', 'other_text'),
+    );
+  }
+
+  if (module_exists('options_element')) {
+    $options = _webform_select_options($component['extra']['items']);
+
+    $form['items'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Options'),
+      '#collapsible' => TRUE,
+      '#attributes' => array('class' => array('webform-options-element')),
+      '#element_validate' => array('_webform_edit_validate_options'),
+    );
+
+    $form['items']['options'] = array(
+      '#type' => 'options',
+      '#limit' => 500,
+      '#optgroups' => $component['extra']['aslist'],
+      '#multiple' => $component['extra']['multiple'],
+      '#multiple_toggle' => t('Multiple'),
+      '#default_value' => $component['value'],
+      '#options' => $options,
+      '#key_type' => 'mixed',
+      '#key_type_toggle' => t('Customize keys (Advanced)'),
+      '#key_type_toggled' => $component['extra']['custom_keys'],
+      '#weight' => 1,
+    );
+
+    $form['items']['options']['option_settings'] = $other;
+  }
+  else {
+    $form['extra']['items'] = array(
+      '#type' => 'textarea',
+      '#title' => t('Options'),
+      '#default_value' => $component['extra']['items'],
+      '#description' => t('<strong>Key-value pairs MUST be specified as "safe_key|Some readable option"</strong>. Only alphanumeric characters and underscores are allowed as a key. One option per line. Option groups may be specified with &lt;Group Name&gt;. &lt;&gt; can be used to insert items at the root of the menu after specifying a group.') . theme('webform_token_help'),
+      '#cols' => 60,
+      '#rows' => 5,
+      '#weight' => -2,
+      '#required' => TRUE,
+      '#element_validate' => array('_webform_edit_validate_select'),
+    );
+    $form['extra'] = array_merge($form['extra'], $other);
+    $form['value'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Default value'),
+      '#default_value' => $component['value'],
+      '#description' => t('The default value of the field. For multiple selects use commas to separate multiple defaults.') . theme('webform_token_help'),
+      '#size' => 60,
+      '#maxlength' => 256,
+      '#weight' => 0,
+    );
+    $form['extra']['multiple'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Multiple'),
+      '#default_value' => $component['extra']['multiple'],
+      '#description' => t('Check this option if the user should be allowed to choose multiple values.'),
+    );
+  }
+
+  $form['display']['aslist'] = array(
     '#type' => 'checkbox',
     '#title' => t('Listbox'),
     '#default_value' => $component['extra']['aslist'],
-    '#description' => t('Check this option if you want the select component to be of listbox type instead of radiobuttons or checkboxes.'),
-  );
-  $form['extra']['other_option'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Allow "Other..." option'),
-    '#default_value' => $component['extra']['other_option'],
-    '#description' => t('Check this option if you want to allow users to enter an option not on the list.'),
-    '#access' => module_exists('select_or_other'),
-  );
-  $form['extra']['other_text'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Text for "Other..." option'),
-    '#default_value' => $component['extra']['other_text'],
-    '#description' => t('If allowing other options, enter text to be used for other-enabling option.'),
-    '#access' => module_exists('select_or_other'),
+    '#description' => t('Check this option if you want the select component to be of listbox type instead of radio buttons or checkboxes.'),
+    '#parents' => array('extra', 'aslist'),
   );
   $form['display']['optrand'] = array(
     '#type' => 'checkbox',
@@ -162,6 +199,28 @@
 }
 
 /**
+ * Set the appropriate webform values when using the options element module.
+ */
+function _webform_edit_validate_options($element, &$form_state) {
+  $key = end($element['#parents']);
+  $element_options = $form_state['values'][$key]['options'];
+  unset($form_state['values'][$key]);
+
+  $form_state['values']['extra'][$key] = form_options_to_text($element_options['options'], 'custom');
+
+  // Options saved for select components.
+  if ($key == 'items') {
+    $form_state['values']['extra']['multiple'] = $element_options['multiple'];
+    $form_state['values']['extra']['custom_keys'] = $element_options['custom_keys'];
+    $form_state['values']['value'] = is_array($element_options['default_value']) ? implode(', ', $element_options['default_value']) : $element_options['default_value'];
+  }
+  // Options saved for grid components.
+  else {
+    $form_state['values']['extra']['custom_' . rtrim($key, 's') . '_keys'] = $element_options['custom_keys'];
+  }
+}
+
+/**
  * Implementation of _webform_render_component().
  */
 function _webform_render_select($component, $value = NULL, $filter = TRUE) {
@@ -209,7 +268,7 @@
     if ($component['extra']['multiple']) {
       $varray = array_filter(explode(',', $default_value));
       foreach ($varray as $key => $v) {
-        $element['#default_value'][] = $v;
+        $element['#default_value'][] = trim($v);
       }
     }
     else {
Index: includes/webform.components.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/includes/webform.components.inc,v
retrieving revision 1.31
diff -u -r1.31 webform.components.inc
--- includes/webform.components.inc	21 Mar 2010 03:04:03 -0000	1.31
+++ includes/webform.components.inc	25 Mar 2010 00:46:23 -0000
@@ -319,7 +319,7 @@
     '#title' => t('Label'),
     '#description' => t('This is used as a descriptive label when displaying this form element.'),
     '#required' => TRUE,
-    '#weight' => -3,
+    '#weight' => -10,
     '#maxlength' => 255,
   );
   $form['form_key'] = array(
@@ -328,7 +328,7 @@
     '#title' => t('Field Key'),
     '#description' => t('Enter a machine readable key for this form element. May contain only lowercase alphanumeric characters and underscores. This key will be used as the name attribute of the form element. This value has no effect on the way data is saved, but may be helpful if using Additional Processing or Validation code.'),
     '#required' => TRUE,
-    '#weight' => -2,
+    '#weight' => -9,
   );
   $form['extra']['description'] = array(
     '#type' => 'textarea',
@@ -344,6 +344,7 @@
     '#title' => t('Display'),
     '#collapsible' => TRUE,
     '#collapsed' => FALSE,
+    '#weight' => 8,
   );
 
   // Validation settings.
@@ -352,6 +353,7 @@
     '#title' => t('Validation'),
     '#collapsible' => TRUE,
     '#collapsed' => FALSE,
+    '#weight' => 5,
   );
   if (webform_component_feature($component['type'], 'required')) {
     $form['validation']['mandatory'] = array(
@@ -425,7 +427,7 @@
   }
   $conditional_components = array_slice($conditional_components, 0, $last_pagebreak_slice, TRUE);
   $form['conditional'] = array(
-    '#weight' => 5,
+    '#weight' => 10,
     '#type' => 'fieldset',
     '#title' => t('Conditional rules'),
     '#collapsible' => TRUE,
