You are here

function _webform_edit_number in Webform 7.4

Same name and namespace in other branches
  1. 6.3 components/number.inc \_webform_edit_number()
  2. 7.3 components/number.inc \_webform_edit_number()

Implements _webform_edit_component().

File

components/number.inc, line 73
Webform module number component.

Code

function _webform_edit_number($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['display']['type'] = array(
    '#type' => 'radios',
    '#title' => t('Element type'),
    '#options' => array(
      'textfield' => t('Text field'),
      'select' => t('Select list'),
    ),
    '#default_value' => $component['extra']['type'],
    '#description' => t('A minimum and maximum value are required if displaying as a select.'),
    '#weight' => -1,
    '#parents' => array(
      'extra',
      'type',
    ),
  );
  $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('Prefix text placed to the left of the field'),
    '#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('Postfix text placed to the right of the field'),
    '#default_value' => $component['extra']['field_suffix'],
    '#description' => t('Examples: lb, kg, %.'),
    '#size' => 20,
    '#maxlength' => 127,
    '#weight' => 1.2,
    '#parents' => array(
      'extra',
      'field_suffix',
    ),
  );
  $form['display']['disabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Disabled'),
    '#return_value' => 1,
    '#description' => t('Make this field non-editable. Useful for displaying default value. Changeable via JavaScript or developer tools.'),
    '#weight' => 11,
    '#default_value' => $component['extra']['disabled'],
    '#parents' => array(
      'extra',
      'disabled',
    ),
  );
  $form['display']['decimals'] = array(
    '#type' => 'select',
    '#title' => t('Decimal places'),
    '#options' => array(
      '' => t('Automatic'),
    ) + drupal_map_assoc(range(0, 10)),
    '#description' => t('Automatic will display up to @count decimals places if needed. A value of "2" is common to format currency amounts.', array(
      '@count' => '4',
    )),
    '#default_value' => $component['extra']['decimals'],
    '#weight' => 2,
    '#parents' => array(
      'extra',
      'decimals',
    ),
    '#element_validate' => array(
      '_webform_edit_number_validate',
    ),
  );
  $form['display']['separator'] = array(
    '#type' => 'select',
    '#title' => t('Thousands separator'),
    '#options' => array(
      ',' => t('Comma (,)'),
      '.' => t('Period (.)'),
      ' ' => t('Space ( )'),
      '' => t('None'),
    ),
    '#default_value' => $component['extra']['separator'],
    '#weight' => 3,
    '#parents' => array(
      'extra',
      'separator',
    ),
    '#element_validate' => array(
      '_webform_edit_number_validate',
    ),
  );
  $form['display']['point'] = array(
    '#type' => 'select',
    '#title' => t('Decimal point'),
    '#options' => array(
      ',' => t('Comma (,)'),
      '.' => t('Period (.)'),
    ),
    '#default_value' => $component['extra']['point'],
    '#weight' => 4,
    '#parents' => array(
      'extra',
      'point',
    ),
    '#element_validate' => array(
      '_webform_edit_number_validate',
    ),
  );
  $form['validation']['unique'] = array(
    '#type' => 'checkbox',
    '#title' => t('Unique'),
    '#return_value' => 1,
    '#description' => t('Check that all entered values for this field are unique. The same value is not allowed to be used twice.'),
    '#weight' => 1,
    '#default_value' => $component['extra']['unique'],
    '#parents' => array(
      'extra',
      'unique',
    ),
  );
  $form['validation']['integer'] = array(
    '#type' => 'checkbox',
    '#title' => t('Integer'),
    '#return_value' => 1,
    '#description' => t('Permit only integer values as input. For example, 12.34 would be invalid.'),
    '#weight' => 1.5,
    '#default_value' => $component['extra']['integer'],
    '#parents' => array(
      'extra',
      'integer',
    ),
  );
  $form['validation']['min'] = array(
    '#type' => 'textfield',
    '#title' => t('Minimum'),
    '#default_value' => $component['extra']['min'],
    '#description' => t('Minimum numeric value. For example, 0 would ensure non-negative numbers.'),
    '#size' => 5,
    '#maxlength' => 10,
    '#weight' => 2.1,
    '#parents' => array(
      'extra',
      'min',
    ),
    '#element_validate' => array(
      '_webform_edit_number_validate',
    ),
  );
  $form['validation']['max'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum'),
    '#default_value' => $component['extra']['max'],
    '#description' => t('Maximum numeric value. This may also determine the display width of your field.'),
    '#size' => 5,
    '#maxlength' => 10,
    '#weight' => 2.2,
    '#parents' => array(
      'extra',
      'max',
    ),
    '#element_validate' => array(
      '_webform_edit_number_validate',
    ),
  );
  $form['validation']['step'] = array(
    '#type' => 'textfield',
    '#title' => t('Step'),
    '#default_value' => $component['extra']['step'],
    '#description' => t('Limit options to a specific increment. For example, a step of "5" would allow values 5, 10, 15, etc.'),
    '#size' => 5,
    '#maxlength' => 10,
    '#weight' => 3,
    '#parents' => array(
      'extra',
      'step',
    ),
    '#element_validate' => array(
      '_webform_edit_number_validate',
    ),
  );

  // Analysis settings.
  $form['analysis'] = array(
    '#type' => 'fieldset',
    '#title' => t('Analysis'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#weight' => 10,
  );
  $form['analysis']['excludezero'] = array(
    '#type' => 'checkbox',
    '#title' => t('Exclude zero'),
    '#return_value' => 1,
    '#description' => t('Exclude entries of zero (or blank) when counting submissions to calculate average and standard deviation.'),
    '#weight' => 1.5,
    '#default_value' => $component['extra']['excludezero'],
    '#parents' => array(
      'extra',
      'excludezero',
    ),
  );
  return $form;
}