You are here

function clientside_validation_html5 in Clientside Validation 7

1 call to clientside_validation_html5()
clientside_validation_html5_after_build_recurse in clientside_validation_html5/clientside_validation_html5.module
5 string references to 'clientside_validation_html5'
clientside_validation_html5_clientside_validation_form_alter in clientside_validation_html5/clientside_validation_html5.module
@file Add clientside validation support for html5 elements
clientside_validation_html5_clientside_validation_webform_alter in clientside_validation_html5/clientside_validation_html5.module
clientside_validation_settings_form in ./clientside_validation.admin.inc
clientside_validation_update_7102 in ./clientside_validation.install
Dependencies changed, enable the right modules.
clientside_validation_webform_after_build_recurse in clientside_validation_webform/clientside_validation_webform.module

File

clientside_validation_html5/clientside_validation_html5.module, line 39
Add clientside validation support for html5 elements

Code

function clientside_validation_html5($form_id, $element, &$js_rules) {
  static $multiples = array();
  if (isset($element['#name'])) {
    $el_name = $element['#name'];
    $el_title = $el_name;
    if (isset($element['#title'])) {
      $el_title = $element['#title'];
    }
    $is_multiple = FALSE;
    if (isset($element['#multiple'])) {
      $is_multiple = $element['#multiple'];
    }
    if ($element['#type'] == 'color') {

      //color elements are required by design, see: http://dev.w3.org/html5/spec/Overview.html#colors

      //"If input is not exactly seven characters long, then return an error."
      $element['#required'] = TRUE;
    }
    $required_error = isset($element['#required_error']) ? $element['#required_error'] : '';
    _clientside_validation_set_required($el_name, $el_title, isset($element['#required']) ? $element['#required'] : FALSE, $js_rules, $required_error);
    if (isset($element['#pattern'])) {
      _clientside_validation_set_regex($el_name, $el_title, $js_rules, $element['#pattern']);
    }
    if (isset($element['#maxlength']) && $element['#maxlength'] > 0) {
      _clientside_validation_set_minmaxlength($el_name, $el_title, '', $element['#maxlength'], $js_rules);
    }
    switch ($element['#type']) {
      case 'range':
      case 'rangefield':
        $default_min = 0;
        $default_max = 100;
      case 'number':
      case 'numberfield':
        if (!isset($default_min)) {
          $default_min = '';
          $default_max = '';
        }
        $min = isset($element['#min']) ? $element['#min'] : $default_min;
        $max = isset($element['#max']) ? $element['#max'] : $default_max;
        $step = isset($element['#step']) ? $element['#step'] : 1;
        $is_decimal = drupal_strtolower($step) == 'any' || (floor($step) != $step || floor($min) != $min);
        if ($is_decimal) {
          _clientside_validation_set_number_decimal($el_name, $el_title, '.', $js_rules);
        }
        else {
          _clientside_validation_set_number($el_name, $el_title, $js_rules);
        }
        if (!empty($min) || !empty($max)) {
          _clientside_validation_set_minmax_html5($el_name, $el_title, $min, $max, $step, $js_rules);
        }
        break;
      case 'url':
      case 'urlfield':
        _clientside_validation_set_url($el_name, $el_title, $js_rules);
        break;
      case 'email':
      case 'emailfield':
        _clientside_validation_set_email($el_name, $el_title, $js_rules);
        break;
      case 'color':
        _clientside_validation_set_html5_color($el_name, $el_title, $js_rules);
    }
  }
}