Commit 2849f216 authored by Jelle Sebreghts's avatar Jelle Sebreghts
Browse files

already added support for #742344

parent 22d67665
......@@ -484,10 +484,11 @@ function _clientside_validation_set_extensions($name, $extensions, &$js_rules) {
/**
* Set validation rule for checkboxes.
*/
function _clientside_validation_set_checkboxgroup_minmax($name, $title, $id, &$js_rules, $min = 1, $max = 99) {
function _clientside_validation_set_checkboxgroup_minmax($name, $title, $id, &$js_rules, $message = '', $min = 1, $max = 99) {
$title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
$message = empty($message) ? t('!name field is required.', array('!name' => $title)) : $message;
$js_rules[$name]['checkboxgroupminmax'] = array($min, $max, $id);
$js_rules[$name]['messages']['checkboxgroupminmax'] = t('!name field is required.', array('!name' => $title));
$js_rules[$name]['messages']['checkboxgroupminmax'] = $message;
}
/**
......
......@@ -37,6 +37,7 @@ function clientside_validation_regular($form_id, $element, &$js_rules) {
if (isset($element['#multiple'])) {
$is_multiple = $element['#multiple'];
}
$required_error = isset($element['#required_error']) ? $element['#required_error'] : '';
switch ($element['#type']) {
case 'textfield':
case 'password':
......@@ -50,12 +51,12 @@ function clientside_validation_regular($form_id, $element, &$js_rules) {
if ($is_multiple) {
// Only first field is required
if (!isset($multiples[$form_id][$el_name])) {
_clientside_validation_set_required($el_name, $el_title, $element['#required'], $js_rules);
_clientside_validation_set_required($el_name, $el_title, $element['#required'], $js_rules, $required_error);
$multiples[$form_id][$el_name] = 1;
}
}
else {
_clientside_validation_set_required($el_name, $el_title, $element['#required'], $js_rules);
_clientside_validation_set_required($el_name, $el_title, $element['#required'], $js_rules, $required_error);
}
if (isset($element['#maxlength']) && $element['#maxlength'] > 0) {
_clientside_validation_set_minmaxlength($el_name, $el_title, '', $element['#maxlength'], $js_rules);
......@@ -70,21 +71,21 @@ function clientside_validation_regular($form_id, $element, &$js_rules) {
$max = (($is_multiple === TRUE || $is_multiple == 1) ? '' : $is_multiple);
_clientside_validation_set_minmaxlength($el_name, $el_title, $element['#minlength'], $max, $js_rules);
}
_clientside_validation_set_required($el_name, $el_title, $element['#required'], $js_rules);
_clientside_validation_set_required($el_name, $el_title, $element['#required'], $js_rules, $required_error);
break;
case 'radio':
case 'radios':
_clientside_validation_set_required($el_name, $el_title, $element['#required'], $js_rules);
_clientside_validation_set_required($el_name, $el_title, $element['#required'], $js_rules, $required_error);
break;
case 'checkbox':
case 'checkboxes':
$is_multiple = (isset($element['#options']) && count($element['#options']>1));
if ($is_multiple && $element['#required']) {
$id = '#' . $element['#id'];
_clientside_validation_set_checkboxgroup_minmax($element['#name'], $el_title, $id, $js_rules);
_clientside_validation_set_checkboxgroup_minmax($element['#name'], $el_title, $id, $js_rules, $required_error);
}
elseif ($element['#required']) {
_clientside_validation_set_required($el_name, $el_title, $element['#required'], $js_rules);
_clientside_validation_set_required($el_name, $el_title, $element['#required'], $js_rules, $required_error);
}
break;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment