Commit a9a664af authored by Jelle Sebreghts's avatar Jelle Sebreghts
Browse files

Issue #1533664 by ramsegal: Fixed custom messages when using fapi integration.

parent ed386396
...@@ -345,13 +345,13 @@ function _clientside_validation_set_number($name, $title, &$js_rules, $message = ...@@ -345,13 +345,13 @@ function _clientside_validation_set_number($name, $title, &$js_rules, $message =
/** /**
* Set validation rule for decimal fields. * Set validation rule for decimal fields.
*/ */
function _clientside_validation_set_number_decimal($name, $title, $decimalpoint, &$js_rules) { function _clientside_validation_set_number_decimal($name, $title, $decimalpoint, &$js_rules, $message = '') {
$title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', ''); $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
if ($decimalpoint == '.') { if ($decimalpoint == '.') {
$js_rules[$name]['number'] = TRUE; $js_rules[$name]['number'] = TRUE;
$variables = array( $variables = array(
'message' => '!title field accepts only numbers (use a \'.\' as decimal point).', 'message' => empty($message) ? '!title field accepts only numbers (use a \'.\' as decimal point).' : $message,
'placeholders' => array('!title' => $title), 'placeholders' => empty($message) ? array('!title' => $title) : array(),
'error_type' => 'number', 'error_type' => 'number',
'element_name' => $name, 'element_name' => $name,
); );
...@@ -360,8 +360,8 @@ function _clientside_validation_set_number_decimal($name, $title, $decimalpoint, ...@@ -360,8 +360,8 @@ function _clientside_validation_set_number_decimal($name, $title, $decimalpoint,
else { else {
$js_rules[$name]['numberDE'] = TRUE; $js_rules[$name]['numberDE'] = TRUE;
$variables = array( $variables = array(
'message' => '!title field accepts only numbers (use a \',\' as decimal point).', 'message' => empty($message) ? '!title field accepts only numbers (use a \',\' as decimal point).' : $message,
'placeholers' => array('!title' => $title), 'placeholers' => empty($message) ? array('!title' => $title) : array(),
'error_type' => 'number', 'error_type' => 'number',
'element_name' => $name, 'element_name' => $name,
); );
...@@ -896,12 +896,12 @@ function _clientside_validation_set_checkboxgroup_minmax($name, $title, $id, &$j ...@@ -896,12 +896,12 @@ function _clientside_validation_set_checkboxgroup_minmax($name, $title, $id, &$j
/** /**
* Set validation rule for email fields. * Set validation rule for email fields.
*/ */
function _clientside_validation_set_email($name, $title, &$js_rules) { function _clientside_validation_set_email($name, $title, &$js_rules, $message = '') {
$title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', ''); $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
$js_rules[$name]['email'] = TRUE; $js_rules[$name]['email'] = TRUE;
$variables = array( $variables = array(
'message' => 'The value in !title is not a valid email address.', 'message' => empty($message) ? 'The value in !title is not a valid email address.' : $message,
'placeholders' => array('!title' => $title), 'placeholders' => empty($message) ? array('!title' => $title) : array(),
'error_type' => 'email', 'error_type' => 'email',
'element_name' => $name 'element_name' => $name
); );
...@@ -911,11 +911,12 @@ function _clientside_validation_set_email($name, $title, &$js_rules) { ...@@ -911,11 +911,12 @@ function _clientside_validation_set_email($name, $title, &$js_rules) {
/** /**
* Set validation rule for url fields. * Set validation rule for url fields.
*/ */
function _clientside_validation_set_url($name, $title, &$js_rules) { function _clientside_validation_set_url($name, $title, &$js_rules, $message = '') {
$title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', ''); $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
$js_rules[$name]['url'] = TRUE; $js_rules[$name]['url'] = TRUE;
$variables = array( $variables = array(
'message' => 'The value in !title is not a valid url.', 'placeholders' => array('!title' => $title), 'message' => empty($message) ? 'The value in !title is not a valid url.' : $message,
'placeholders' => empty($message) ? array('!title' => $title) : array(),
'error_type' => 'url', 'error_type' => 'url',
'element_name' => $name 'element_name' => $name
); );
......
...@@ -110,24 +110,24 @@ function _clientside_validation_set_fapi_validation($element, $rule, $params, &$ ...@@ -110,24 +110,24 @@ function _clientside_validation_set_fapi_validation($element, $rule, $params, &$
break; break;
case 'fapi_validation_rule_numeric': case 'fapi_validation_rule_numeric':
_clientside_validation_set_number_decimal($name, $title, '.', $js_rules); _clientside_validation_set_number_decimal($name, $title, '.', $js_rules, $message);
break; break;
case 'fapi_validation_rule_email': case 'fapi_validation_rule_email':
_clientside_validation_set_email($name, $title, $js_rules); _clientside_validation_set_email($name, $title, $js_rules, $message);
break; break;
case 'fapi_validation_rule_length': case 'fapi_validation_rule_length':
if (count($params) == 1) { if (count($params) == 1) {
_clientside_validation_set_minmaxlength($name, $title, '', $params[0], $js_rules); _clientside_validation_set_minmaxlength($name, $title, '', $params[0], $js_rules, $message);
} }
elseif (count($params) == 2) { elseif (count($params) == 2) {
_clientside_validation_set_minmaxlength($name, $title, $params[0], $params[1], $js_rules); _clientside_validation_set_minmaxlength($name, $title, $params[0], $params[1], $js_rules, $message);
} }
break; break;
case 'fapi_validation_rule_url': case 'fapi_validation_rule_url':
_clientside_validation_set_url($name, $title, $js_rules); _clientside_validation_set_url($name, $title, $js_rules, $message);
break; break;
case 'fapi_validation_rule_chars': case 'fapi_validation_rule_chars':
_clientside_validation_set_specific_values($name, $title, $params, $js_rules); _clientside_validation_set_specific_values($name, $title, $params, $js_rules, $message);
break; break;
case 'fapi_validation_rule_decimal': case 'fapi_validation_rule_decimal':
if (count($params) == 2) { if (count($params) == 2) {
......
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