You are here

function _element_validate_limit in Formatted Number 7

Validate the element for min/max limits.

1 string reference to '_element_validate_limit'
formatted_number_field_instance_settings_form in ./formatted_number.module
Implements hook_field_instance_settings_form().

File

./formatted_number.module, line 192
Defines numeric field types where the thousand and decimal separators are inherited from the Format Number API module.

Code

function _element_validate_limit($element, &$form_state) {
  $value = $element['#value'];
  $field_name = $form_state['values']['instance']['field_name'];
  $field = $form_state['field'][$field_name][LANGUAGE_NONE]['field'];
  if ($value != '' && !is_numeric($value)) {
    form_error($element, t('%name must be a number.', array(
      '%name' => $element['#title'],
    )));
  }
  if ($value != '' && isset($field['settings']['min'])) {
    if ($element['#name'] == 'instance[settings][min]' && $value < $field['settings']['min']) {
      form_error($element, t('%name: the value may be no less than %min.', array(
        '%name' => $element['#title'],
        '%min' => $field['settings']['min'],
      )));
    }
    if ($element['#name'] == 'instance[settings][max]' && $value > $field['settings']['max']) {
      form_error($element, t('%name: the value may be no greater than %max.', array(
        '%name' => $element['#title'],
        '%max' => $field['settings']['max'],
      )));
    }
  }
}