function _webform_edit_select in Webform 6.3
Same name and namespace in other branches
- 5.2 components/select.inc \_webform_edit_select()
- 5 components/select.inc \_webform_edit_select()
- 6.2 components/select.inc \_webform_edit_select()
- 7.4 components/select.inc \_webform_edit_select()
- 7.3 components/select.inc \_webform_edit_select()
Implements _webform_edit_component().
File
- components/
select.inc, line 50 - Webform module multiple select component.
Code
function _webform_edit_select($component) {
$form = array();
drupal_add_js(drupal_get_path('module', 'webform') . '/js/select-admin.js', 'module', 'header', FALSE, TRUE, FALSE);
drupal_add_js(array(
'webform' => array(
'selectOptionsUrl' => url('webform/ajax/options/' . $component['nid']),
),
), 'setting');
$other = array();
if ($info = _webform_select_options_info()) {
$options = array(
'' => t('None'),
);
foreach ($info as $name => $source) {
$options[$name] = $source['title'];
}
$other['options_source'] = array(
'#title' => t('Load a pre-built option list'),
'#type' => 'select',
'#options' => $options,
'#default_value' => $component['extra']['options_source'],
'#weight' => 1,
'#description' => t('Use a pre-built list of options rather than entering options manually. Options will not be editable if using pre-built list.'),
'#parents' => array(
'extra',
'options_source',
),
'#weight' => 5,
);
}
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',
),
'#weight' => 2,
);
$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',
),
'#weight' => 3,
);
}
if (module_exists('options_element')) {
$options = _webform_select_options($component, FALSE, FALSE);
$form['items'] = array(
'#type' => 'fieldset',
'#title' => t('Options'),
'#collapsible' => TRUE,
'#attributes' => array(
'class' => 'webform-options-element',
),
'#element_validate' => array(
'_webform_edit_validate_options',
),
'#weight' => 2,
);
$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,
'#options_readonly' => !empty($component['extra']['options_source']),
'#key_type' => 'mixed',
'#key_type_toggle' => t('Customize keys (Advanced)'),
'#key_type_toggled' => $component['extra']['custom_keys'],
'#default_value_pattern' => '^%.+\\[.+\\]$',
'#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>. Use of only alphanumeric characters and underscores is recommended in keys. One option per line. Option groups may be specified with <Group Name>. <> 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' => 0,
'#required' => TRUE,
'#wysiwyg' => FALSE,
'#element_validate' => array(
'_webform_edit_validate_select',
),
);
if (!empty($component['extra']['options_source'])) {
$form['extra']['items']['#attributes'] = array(
'readonly' => 'readonly',
);
}
$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 identified by its key. For multiple selects use commas to separate multiple defaults.') . theme('webform_token_help'),
'#size' => 60,
'#maxlength' => 1024,
'#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.'),
'#weight' => 0,
);
}
$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 displayed as a select list box instead of radio buttons or checkboxes. Option groups (nested options) are only supported with listbox components.'),
'#parents' => array(
'extra',
'aslist',
),
);
$form['display']['optrand'] = array(
'#type' => 'checkbox',
'#title' => t('Randomize options'),
'#default_value' => $component['extra']['optrand'],
'#description' => t('Randomizes the order of the options when they are displayed in the form.'),
'#parents' => array(
'extra',
'optrand',
),
);
return $form;
}