You are here

function _webform_edit_autocomplete in Webform Autocomplete 7.2

Same name and namespace in other branches
  1. 7 autocomplete.inc \_webform_edit_autocomplete()

Implements _webform_edit_component().

File

./autocomplete.inc, line 30
Autocomplete component.

Code

function _webform_edit_autocomplete($component) {
  $form = array();
  $form['value'] = array(
    '#type' => 'textfield',
    '#title' => t('Default value'),
    '#default_value' => $component['value'],
    '#description' => t('The default value of the field.') . theme('webform_token_help'),
    '#size' => 60,
    '#maxlength' => 1024,
    '#weight' => 0,
  );
  $form['options']['autocomplete_items'] = array(
    '#type' => 'textarea',
    '#title' => t('Options'),
    '#default_value' => $component['extra']['autocomplete_items'],
    '#description' => t('One value per line. Unlike select elements, this field does not use key|value pairs - enter values only.'),
    '#cols' => 60,
    '#rows' => 5,
    '#weight' => 0,
    '#required' => FALSE,
    '#wysiwyg' => FALSE,
    '#parents' => array(
      'extra',
      'autocomplete_items',
    ),
  );
  $form['display']['autocomplete_result_count'] = array(
    '#type' => 'textfield',
    '#title' => t('Result Count'),
    '#default_value' => $component['extra']['autocomplete_result_count'],
    '#description' => t('Maximum number of autocomplete results to display.'),
    '#size' => 5,
    '#weight' => -1,
    '#maxlength' => 2,
    '#required' => TRUE,
    '#parents' => array(
      'extra',
      'autocomplete_result_count',
    ),
  );
  $form['display']['width'] = array(
    '#type' => 'textfield',
    '#title' => t('Width'),
    '#default_value' => $component['extra']['width'],
    '#description' => t('Width of the textfield.') . ' ' . t('Leaving blank will use the default size.'),
    '#size' => 5,
    '#maxlength' => 10,
    '#weight' => 0,
    '#parents' => array(
      'extra',
      'width',
    ),
  );
  $form['display']['placeholder'] = array(
    '#type' => 'textfield',
    '#title' => t('Placeholder'),
    '#default_value' => $component['extra']['placeholder'],
    '#description' => t('The placeholder will be shown in the field until the user starts entering a value.'),
    '#weight' => 1,
    '#parents' => array(
      'extra',
      'placeholder',
    ),
  );
  $form['display']['field_prefix'] = array(
    '#type' => 'textfield',
    '#title' => t('Label placed to the left of the textfield'),
    '#default_value' => $component['extra']['field_prefix'],
    '#description' => t('Examples: $, #, -.'),
    '#size' => 20,
    '#maxlength' => 127,
    '#weight' => 1.1,
    '#parents' => array(
      'extra',
      'field_prefix',
    ),
  );
  $form['display']['field_suffix'] = array(
    '#type' => 'textfield',
    '#title' => t('Label placed to the right of the textfield'),
    '#default_value' => $component['extra']['field_suffix'],
    '#description' => t('Examples: lb, kg, %.'),
    '#size' => 20,
    '#maxlength' => 127,
    '#weight' => 1.2,
    '#parents' => array(
      'extra',
      'field_suffix',
    ),
  );
  $form['options']['autocomplete_existing'] = array(
    '#type' => 'checkbox',
    '#title' => t('Autocomplete from existing submissions'),
    '#return_value' => 1,
    '#description' => t('Autocomplete from previous values entered in this field. If options are entered above, autocomplete will select from both.'),
    '#weight' => 1,
    '#default_value' => $component['extra']['autocomplete_existing'],
    '#parents' => array(
      'extra',
      'autocomplete_existing',
    ),
  );
  if (module_exists('taxonomy')) {
    foreach (taxonomy_vocabulary_get_names() as $voc) {
      $options[$voc->machine_name] = $voc->name;
    }
    natcasesort($options);
    $form['options']['autocomplete_taxonomy'] = array(
      '#type' => 'select',
      '#title' => t('Autocomplete from existing taxonomy terms'),
      '#options' => array(
        0 => t('Disabled'),
      ) + $options,
      '#description' => t('Autocomplete from term names entered in this taxonomy vocabulary. If options are entered above, autocomplete will select from both.'),
      '#weight' => 1,
      '#default_value' => $component['extra']['autocomplete_taxonomy'],
      '#parents' => array(
        'extra',
        'autocomplete_taxonomy',
      ),
    );
  }
  $form['options']['autocomplete_match_rule'] = array(
    '#type' => 'select',
    '#title' => t('Match Rule'),
    '#options' => array(
      WEBFORM_AUTOCOMPLETE_MATCH_BEGIN => t('starts with'),
      WEBFORM_AUTOCOMPLETE_MATCH_CONTAINS => t('contains'),
      WEBFORM_AUTOCOMPLETE_MATCH_END => t('ends with'),
    ),
    '#parents' => array(
      'extra',
      'autocomplete_match_rule',
    ),
    '#default_value' => $component['extra']['autocomplete_match_rule'],
  );
  $form['validation']['unique'] = array(
    '#type' => 'checkbox',
    '#title' => t('Unique'),
    '#return_value' => 1,
    '#description' => t('Require all entered values for this field to be unique. The same value will not autocomplete twice.'),
    '#weight' => 1,
    '#default_value' => $component['extra']['unique'],
    '#parents' => array(
      'extra',
      'unique',
    ),
  );
  $form['validation']['autocomplete_restrict'] = array(
    '#type' => 'checkbox',
    '#title' => t('Restrict to listed values'),
    '#return_value' => 1,
    '#description' => t('Only allow options entered here to be chosen. Other input will be rejected.'),
    '#weight' => 1,
    '#default_value' => $component['extra']['autocomplete_restrict'],
    '#parents' => array(
      'extra',
      'autocomplete_restrict',
    ),
  );
  $form['#validate'][] = '_webform_autocomplete_admin_validate';
  return $form;
}