Commit 70db63a8 authored by Jelle Sebreghts's avatar Jelle Sebreghts
Browse files

new implementation of the theme function, see Issue #1304512 by yang.wilby:...

new implementation of the theme function, see Issue #1304512 by yang.wilby: Added How to customize an error message when the user doesn't fill out a mandatory field.
parent 640e209c
This diff is collapsed.
......@@ -76,12 +76,6 @@ function _clientside_validation_set_fapi_validation($element, $rule, $params, &$
if (isset($element['#title'])) {
$title = $element['#title'];
}
if (strpos($message, '%field') !== FALSE) {
$message = theme('clientside_error', array('message' => $message, 'placeholders' => array('%field' => variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', ''))));
}
else {
$message = theme('clientside_error', array('message' => $message));
}
$expressions = array(
'fapi_validation_rule_alpha' => '/^[\pL]++$/uD',
'fapi_validation_rule_alpha_numeric' => '/^[\pL\pN]++$/uD',
......@@ -92,15 +86,24 @@ function _clientside_validation_set_fapi_validation($element, $rule, $params, &$
);
switch ($callback) {
case 'fapi_validation_rule_alpha':
$type = 'alpha';
case 'fapi_validation_rule_alpha_numeric':
$type = 'alpha numeric';
case 'fapi_validation_rule_ipv4':
$type = 'ipv4';
case 'fapi_validation_rule_alpha_dash':
$type = 'alpha dash';
case 'fapi_validation_rule_digit':
$type = 'digit';
case 'fapi_validation_rule_regexp':
if ($callback == 'fapi_validation_rule_regexp') {
$expressions['fapi_validation_rule_regexp'] = $params[0];
$expressions['fapi_validation_rule_regexp'] = $params[1][0];
$type = 'regexp';
}
_clientside_validation_set_regex_pcre($name, $title, $js_rules, $expressions[$callback], $message);
if (strpos($message, '%field') !== FALSE) {
$message = t($message, array('%field' => variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '')));
}
_clientside_validation_set_regex_pcre($name, $title, $js_rules, $expressions[$callback], $message, $type);
break;
case 'fapi_validation_rule_numeric':
......@@ -130,7 +133,10 @@ function _clientside_validation_set_fapi_validation($element, $rule, $params, &$
else {
$expression = '/\d+\.\d+/';
}
_clientside_validation_set_regex_pcre($name, $title, $js_rules, $expression, $message);
if (strpos($message, '%field') !== FALSE) {
$message = t($message, array('%field' => variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '')));
}
_clientside_validation_set_regex_pcre($name, $title, $js_rules, $expression, $message, 'decimal');
break;
default:
$context = array('type' => 'fapi', 'rule' => $rule, 'message' => $message, 'params' => $params);
......
......@@ -99,20 +99,79 @@ function _clientside_validation_set_minmax_html5($name, $title, $min, $max, $ste
}
elseif (isset($min) && $min !== '' && isset($max) && $max !== '') {
$js_rules[$name]['Html5Range'] = array($min, $max, $step);
$js_rules[$name]['messages']['Html5Range'] = (empty($message)) ? theme('clientside_error', array('message' => '!name field has to be greater than !min with steps of !step and smaller than !max.', 'placeholders' => array('!name' => $title, '!min' => $min, '!max' => $max, '!step' => $step))) : theme('clientside_error', array('message' => $message));
if (empty($message)) {
$variables = array(
'message' => '!title field has to be greater than !min with steps of !step and smaller than !max.',
'placeholders' => array('!title' => $title, '!min' => $min, '!max' => $max, '!step' => $step),
'error_type' => 'range',
'element_name' => $name,
);
}
else {
$variables = array(
'message' => $message,
'error_type' => 'range',
'element_name' => $name,
);
}
$js_rules[$name]['messages']['Html5Range'] = theme('clientside_error', $variables);
}
elseif (isset($min) && $min !== '') {
$js_rules[$name]['Html5Min'] = array($min, $step);
$js_rules[$name]['messages']['Html5Min'] = (empty($message)) ? theme('clientside_error', array('message' => '!name field has to be greater than !min with steps of !step.', 'placeholders' => array('!name' => $title, '!min' => $min, '!step' => $step))) : theme('clientside_error', array('message' => $message));
if (empty($message)) {
$variables = array(
'message' => '!title field has to be greater than !min with steps of !step.',
'placeholders' => array('!title' => $title, '!min' => $min, '!step' => $step),
'error_type' => 'min',
'element_name' => $name,
);
}
else {
$variables = array(
'message' => $message,
'error_type' => 'min',
'element_name' => $name,
);
}
$js_rules[$name]['messages']['Html5Min'] = theme('clientside_error', $variables);
}
elseif (isset($max) && $max !== '') {
$js_rules[$name]['Html5Max'] = array($max, $step);
$js_rules[$name]['messages']['Html5Max'] = (empty($message)) ? theme('clientside_error', array('message' => '!name field has to be smaller than !max and must be dividable by !step.', 'placeholders' => array('!name' => $title, '!max' => $max, '!step' => $step))) : theme('clientside_error', array('message' => $message));
if (empty($message)) {
$variables = array(
'message' => '!title field has to be smaller than !max and must be dividable by !step.',
'placeholders' => array('!title' => $title, '!max' => $max, '!step' => $step),
'error_type' => 'max',
'element_name' => $name,
);
}
else {
$variables = array(
'message' => $message,
'error_type' => 'max',
'element_name' => $name,
);
}
$js_rules[$name]['messages']['Html5Max'] = theme('clientside_error', $variables);
}
}
function _clientside_validation_set_html5_color($name, $title, &$js_rules, $message='') {
$title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
$js_rules[$name]['Html5Color'] = TRUE;
$js_rules[$name]['messages']['Html5Color'] = (empty($message)) ? theme('clientside_error', array('message' => '!name field must be a vlid color code', 'placeholders' => array('!name' => $name))) : theme('clientside_error', array('message' => $message));
if (empty($message)) {
$variables = array(
'message' => '!title field must be a vlid color code',
'placeholders' => array('!title' => $title),
'error_type' => 'color',
'element_name' => 'name');
}
else {
$variables = array(
'message' => $message,
'error_type' => 'color',
'element_name' => $name,
);
}
$js_rules[$name]['messages']['Html5Color'] = theme('clientside_error', $variables);
}
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