You are here

function _clientside_validation_set_require_oneof in Clientside Validation 7

Same name and namespace in other branches
  1. 6 clientside_validation.module \_clientside_validation_set_require_oneof()

Set validation rule for "require at least one of several".

1 call to _clientside_validation_set_require_oneof()
clientside_validation_webform_add_webform_validation in clientside_validation_webform/clientside_validation_webform.module
Support webform_validation

File

./clientside_validation.module, line 1272
Add client side validation to forms.

Code

function _clientside_validation_set_require_oneof($names, $titles, $message = "", &$js_rules) {
  $original_message = $message;
  foreach ($names as $key => $name) {
    $temp_titles = $titles;
    unset($temp_titles[$key]);
    if (empty($original_message)) {
      $string_titles = '<ul><li>' . implode('</li><li>', $temp_titles) . '</li></ul>';
      $message = t('!name field is required unless you specify at least one of these items: !items', array(
        '!name' => $titles[$key],
        '!items' => $string_titles,
      ));
    }
    $js_rules[$name]['requireOneOf'] = array_diff($names, array(
      $name,
    ));
    $variables = array(
      'message' => $message,
      'error_type' => 'requireOneOf',
      'element_name' => $name,
    );
    $js_rules[$name]['messages']['requireOneOf'] = theme('clientside_error', $variables);
  }
}