You are here

function range_field in Range 6

Implementation of hook_field().

File

./range.module, line 240
Defines numeric fields within a range of possible values and displays them colored accordingly..

Code

function range_field($op, &$node, $field, &$items, $teaser, $page) {
  switch ($op) {
    case 'validate':
      $allowed_values = content_allowed_values($field);
      if (is_array($items)) {
        foreach ($items as $delta => $item) {
          $error_element = isset($item['_error_element']) ? $item['_error_element'] : '';
          if ($item['value'] != '') {
            if (is_numeric($field['min']) && $item['value'] < $field['min']) {

              //form_set_error($error_element, t('%name: the value may be no smaller than %min.', array('%name' => t($field['widget']['label']), '%min' => $field['min'])));
            }
            if (is_numeric($field['max']) && $item['value'] > $field['max']) {

              //form_set_error($error_element, t('%name: the value may be no larger than %max.', array('%name' => t($field['widget']['label']), '%max' => $field['max'])));
            }
            if (count($allowed_values) && !array_key_exists($item['value'], $allowed_values)) {
              form_set_error($error_element, t('%name: illegal value.', array(
                '%name' => t($field['widget']['label']),
              )));
            }
          }
        }
      }
      break;
  }
}