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

Issue #1434136 by sameer: Fixed PHP Notice in line 226 of clientside_validation_webform().module.

parent 90ee0b01
......@@ -442,18 +442,7 @@
// Min a and maximum b checkboxes from a group
jQuery.validator.addMethod("checkboxgroupminmax", function(value, element, param) {
var validOrNot = $(param[2] + ' input:checked').length >= param[0] && $(param[2] + ' input:checked').length <= param[1];
/* This gives problems */
/*if(!$(element).data('being_validated')) {
var fields = $(param[2] + ' input');
fields.data('being_validated', true).valid();
fields.data('being_validated', false);
}*/
return validOrNot;
}, jQuery.format('Minimum {0}, maximum {1}'));
// Allow integers, same as digits but including a leading '-'
......@@ -717,6 +706,28 @@
return true;
});
// Require one of several
jQuery.validator.addMethod("requireOneOf", function(value, element, param) {
var ret = false;
if (value == "") {
jQuery.each(param, function(index, name) {
if ($("[name='" + name + "']").val().length && !ret) {
ret = true;
}
});
}
else {
$(element).removeClass("error");
ret = true;
}
$(element).blur(function () {
jQuery.each(param, function(index, name) {
$("[name='" + name + "']").valid();
});
});
return ret;
}, jQuery.format('Please fill in at least on of the fields'));
// EAN code
jQuery.validator.addMethod("validEAN", function(value, element, param) {
......
......@@ -698,8 +698,8 @@ function _clientside_validation_set_specific_value($name, $title, $value, &$js_r
$title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
if (empty($message)) {
$variables = array(
'message' => '!title field has to different from !firstone.',
'placeholders' => array('!title' => $title, '!firstone' => $value['name']),
'message' => '!title field has to be one of the following values: !values.',
'placeholders' => array('!title' => $title, '!values' => implode(', ', $value)),
'error_type' => 'specific value',
'element_name' => $name
);
......@@ -923,6 +923,28 @@ function _clientside_validation_set_url($name, $title, &$js_rules) {
$js_rules[$name]['messages']['url'] = theme('clientside_error', $variables);
}
/**
* Set validation rule for "require at least one of several".
*/
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);
}
}
function clientside_validation_drupal_json_encode($var) {
return str_replace(array('<', '>', '&'), array('\u003c', '\u003e', '\u0026'), json_encode($var));
}
......
......@@ -74,15 +74,23 @@ function clientside_validation_webform_after_build_recurse($form_id, &$form, &$f
_clientside_validation_set_required($element['#name'], $element['#title'], TRUE, $js_rules);
}
}
if ((isset($element['#name']) || isset($element[$element['#webform_component']['form_key']]['#name'])) && isset($element['#webform_component']) && $element['#webform_component']['type'] == 'file' && $element['#webform_component']['mandatory'] == "1") {
$name = isset($element['#name']) ? $element['#name'] : $element[$element['#webform_component']['form_key']]['#name'];
_clientside_validation_set_required($name, $element['#title'], TRUE, $js_rules);
if (isset($element['#webform_component']['extra']['filtering']['types'])) {
$extensions = $element['#webform_component']['extra']['filtering']['types'];
_clientside_validation_set_extensions($name, $extensions, $js_rules);
if (isset($element['#webform_component']) && $element['#webform_component']['type'] == 'file' && $element['#webform_component']['mandatory'] == "1") {
$file_children = element_children($element);
if (count($file_children) > 0) {
foreach ($file_children as $child) {
$file_child = $element[$child];
if (isset($file_child['#name']) && $file_child['#type'] == 'file') {
$name = $file_child['#name'];
_clientside_validation_set_required($name, $element['#title'], TRUE, $js_rules);
if (isset($element['#webform_component']['extra']['filtering']['types'])) {
$extensions = $element['#webform_component']['extra']['filtering']['types'];
_clientside_validation_set_extensions($name, $extensions, $js_rules);
}
}
}
}
}
if (isset($element['#maxlength']) && $element['#maxlength']) {
$message = t('!name field has a max length of !maxl characters.', array('!name' => variable_get('clientside_validation_prefix', '') . $element['#title'] . variable_get('clientside_validation_suffix', ''), '!maxl' => $element['#maxlength']));
_clientside_validation_set_minmaxlength($element['#name'], $element['#title'], '', $element['#maxlength'], $js_rules, $message);
......@@ -118,6 +126,18 @@ function clientside_validation_webform_add_webform_validation($form_id, &$form,
_clientside_validation_set_minmaxlength($component['element_name'], $component['element_title'], '', $webform_validation_rule['data'], $js_rules, $message);
}
break;
case 'min_words':
foreach ($webform_validation_rule['components'] as $component) {
$message = t('!name field must have at least !min words.', array('!name' => variable_get('clientside_validation_prefix', '') . $component['element_title'] . variable_get('clientside_validation_suffix', ''), '!min' => $webform_validation_rule['data']));
_clientside_validation_set_minmax_words($component['element_name'], $component['element_title'], $webform_validation_rule['data'], "", $js_rules);
}
break;
case 'max_words':
foreach ($werbform_validation_rule['components'] as $component) {
$message = t('!name field can not have more than !max words.', array('!name' => variable_get('clientside_validation_prefix', '') . $component['element_title'] . variable_get('clientside_validation_suffix', ''), '!max' => $webform_validation_rule['data']));
_clientside_validation_set_minmax_words($component['element_name'], $component['element_title'], "", $webform_validation_rule['data'], $js_rules);
}
break;
case 'numeric':
$data = $webform_validation_rule['data'];
$range = array('min' => NULL, 'max' => NULL);
......@@ -144,6 +164,27 @@ function clientside_validation_webform_add_webform_validation($form_id, &$form,
}
}
break;
case 'oneofseveral':
case 'oneoftwo':
foreach ($webform_validation_rule['components'] as $component) {
$names[] = $component['element_name'];
$titles[] = variable_get('clientside_validation_prefix', '') . $component['element_title'] . variable_get('clientside_validation_suffix', '');
}
_clientside_validation_set_require_oneof($names, $titles, "", $js_rules);
break;
case 'plain_text':
foreach ($webform_validation_rule['components'] as $component) {
_clientside_validation_set_plain_text($component['element_name'], $component['element_title'], "", $js_rules);
}
break;
case 'blacklist':
$message = (isset($webform_validation_rule['error_message']) && !empty($webform_validation_rule['error_message'])) ? $webform_validation_rule['error_message'] : '';
$blacklist = explode(',', $webform_validation_rule['data']);
$blacklist = array_map('trim', $blacklist);
foreach ($webform_validation_rule['components'] as $component) {
_clientside_validation_set_blacklist($component['element_name'], $component['element_title'], $blacklist, $js_rules, $message);
}
break;
case 'equal':
$others = $webform_validation_rule['components'];
$firstone = array_shift($others);
......@@ -221,6 +262,12 @@ function clientside_validation_webform_add_webform_validation($form_id, &$form,
_clientside_validation_set_regex($component['element_name'], $component['element_title'], $js_rules, $expression, $message);
}
break;
case 'must_be_empty':
foreach ($webform_validation_rule['components'] as $component) {
$message = t('!name field must be empty.', array('!name' => variable_get('clientside_validation_prefix', '') . $component['element_title'] . variable_get('clientside_validation_suffix', '')));
_clientside_validation_set_specific_value($component['element_name'], $component['element_title'], array(""), $js_rules, $message);
}
break;
default:
foreach ($webform_validation_rule['components'] as $component) {
$message = (isset($webform_validation_rule['error_message']) && !empty($webform_validation_rule['error_message'])) ? $webform_validation_rule['error_message'] : t('Invalid value for !name', array('!name' => variable_get('clientside_validation_prefix', '') . $component['element_title'] . variable_get('clientside_validation_suffix', '')));
......@@ -249,17 +296,29 @@ function clientside_validation_webform_add_webform_validation($form_id, &$form,
*/
function _clientside_validation_webform_webform_validation($nid, $form) {
static $webform_validation_rules;
if (!isset($webform_validation_rules[$nid])) {
$current_page = $form['details']['page_num']['#value'];
if (!isset($webform_validation_rules[$nid][$current_page])) {
if (module_exists('webform_validation')) {
$webform_validation_rules[$nid] = webform_validation_get_node_rules($nid);
$node_rules = webform_validation_get_node_rules($nid);
foreach ($node_rules as $rid => $rule) {
foreach ($rule['components'] as $cid => $component) {
if ($form['#node']->webform['components'][$component['cid']]['page_num'] != $current_page) {
unset($node_rules[$rid]['components'][$cid]);
if (empty($node_rules[$rid]['components'])) {
unset($node_rules[$rid]);
}
}
}
}
$webform_validation_rules[$nid][$current_page] = $node_rules;
// add element name to arrays
clientside_validation_webform_webform_validation_add_names($webform_validation_rules[$nid], $form);
clientside_validation_webform_webform_validation_add_names($webform_validation_rules[$nid][$current_page], $form);
}
else {
$webform_validation_rules[$nid] = NULL;
$webform_validation_rules[$nid][$current_page] = NULL;
}
}
return $webform_validation_rules[$nid];
return $webform_validation_rules[$nid][$current_page];
}
function clientside_validation_webform_webform_validation_add_names(&$webform_validation_rules, $form) {
......
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