function _clientside_validation_set_minmaxlength_select in Clientside Validation 7
Set validation rule for fields with a minimum and/or maximum length for select options.
2 calls to _clientside_validation_set_minmaxlength_select()
- clientside_validation_field_validation_regular in clientside_validation_field_validation/
clientside_validation_field_validation.module - clientside_validation_webform_add_webform_validation in clientside_validation_webform/
clientside_validation_webform.module - Support webform_validation
File
- ./
clientside_validation.module, line 807 - Add client side validation to forms.
Code
function _clientside_validation_set_minmaxlength_select($name, $title, $min, $max, &$js_rules, $message = '', $negate = FALSE) {
$title = _clientside_validation_set_title($title);
if ($max == 1) {
$max = '';
}
if (isset($min) && $min !== '' && isset($max) && $max !== '') {
$js_rules[$name]['selectRangelength']['range'] = array(
$min,
$max,
);
$js_rules[$name]['selectRangelength']['negate'] = $negate;
if (empty($message)) {
$variables = array(
'message' => '!title field has to have between !min and !max values.',
'placeholders' => array(
'!title' => $title,
'!min' => $min,
'!max' => $max,
),
'error_type' => 'selectRangelength',
'element_name' => $name,
);
}
else {
$variables = array(
'message' => $message,
'error_type' => 'selectRangelength',
'element_name' => $name,
);
}
$js_rules[$name]['messages']['selectRangelength'] = theme('clientside_error', $variables);
}
elseif (isset($min) && $min !== '') {
$js_rules[$name]['selectMinlength'] = array(
'min' => $min,
'negate' => $negate,
);
if (empty($message)) {
$variables = array(
'message' => '!title field has to have minimal !min values.',
'placeholders' => array(
'!title' => $title,
'!min' => $min,
),
'error_type' => 'selectMinlength',
'element_name' => $name,
);
}
else {
$variables = array(
'message' => $message,
'error_type' => 'selectMinlength',
'element_name' => $name,
);
}
$js_rules[$name]['messages']['selectMinlength'] = theme('clientside_error', $variables);
}
elseif (isset($max) && $max !== '') {
$js_rules[$name]['selectMaxlength'] = array(
'max' => $max,
'negate' => $negate,
);
if (empty($message)) {
$variables = array(
'message' => '!title field has to have maximum !max values.',
'placeholders' => array(
'!title' => $title,
'!max' => $max,
),
'error_type' => 'selectMaxlength',
'element_name' => $name,
);
}
else {
$variables = array(
'message' => $message,
'error_type' => 'selectMaxlength',
'element_name' => $name,
);
}
$js_rules[$name]['messages']['selectMaxlength'] = theme('clientside_error', $variables);
}
}