Commit 46b3a3b9 authored by Jelle Sebreghts's avatar Jelle Sebreghts
Browse files

Issue #1543742 by peskydonut: Added Custom validation using #element_validate().

parent 5ca2a0f0
......@@ -680,13 +680,18 @@ function _clientside_validation_set_equal($name, $title, $value, &$js_rules) {
/**
* Set validation rule for fields that can not be equal to a value from an other field.
*/
function _clientside_validation_set_not_equal($name, $title, $value, &$js_rules, $message = '') {
$js_rules[$name]['notEqualTo'] = ':input[name=\'submitted[' . $value['form_key'] . ']\']';
function _clientside_validation_set_not_equal($name, $title, $element, &$js_rules, $message = '', $webform = FALSE) {
if ($webform) {
$js_rules[$name]['notEqualTo'] = ':input[name=\'submitted[' . $element['form_key'] . ']\']';
}
else {
$js_rules[$name]['notEqualTo'] = ':input[name=\'' . $element['form_key'] . '\']';
}
$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']),
'placeholders' => array('!title' => $title, '!firstone' => $element['name']),
'error_type' => 'notequalto',
'element_name' => $name,
);
......
......@@ -12,10 +12,10 @@ function clientside_validation_form_after_build_recurse($form_id, &$form, &$form
if ($children = array_values(element_children($form))) {
foreach ($children as $index => $item) {
$element = &$form[$item];
$types = array(
/* $types = array(
'textfield', 'textarea', 'select', 'radio', 'checkbox', 'password', 'managed_file', 'file', 'radios', 'checkboxes', 'link_field',
);
if (isset($element['#type']) && in_array($element['#type'], $types)) {
);*/
if (isset($element['#type']) /*&& in_array($element['#type'], $types)*/) {
clientside_validation_regular($form_id, $element, $js_rules, $form_state);
}
clientside_validation_form_after_build_recurse($form_id, $element, $form_state, $js_rules);
......@@ -156,6 +156,10 @@ function clientside_validation_regular($form_id, $element, &$js_rules, $form_sta
break;
}
}
if (isset($element['#element_validate']) && !empty($element['#element_validate'])) {
$context = array('type' => 'element_validate', 'functions' => $element['#element_validate']);
drupal_alter('clientside_validation_rule', $js_rules, $element, $context);
}
}
function clientside_validation_form_field_info_alter(&$info) {
......
......@@ -217,7 +217,7 @@ function clientside_validation_webform_add_webform_validation($form_id, &$form,
$firstone = array_shift($all);
foreach ($all as $component) {
$message = (isset($webform_validation_rule['error_message']) && !empty($webform_validation_rule['error_message'])) ? $webform_validation_rule['error_message'] : '';
_clientside_validation_set_not_equal($component['element_name'], $component['element_title'], $firstone, $js_rules, $message);
_clientside_validation_set_not_equal($component['element_name'], $component['element_title'], $firstone, $js_rules, $message, TRUE);
}
}
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