Commit 1213cdee authored by Jelle Sebreghts's avatar Jelle Sebreghts
Browse files

Issue #1804784 by SeanBannister: Fixed Bug with support for Field Validation Tokens.

parent 721700e9
/*jshint strict:true, browser:true, curly:true, eqeqeq:true, expr:true, forin:true, latedef:true, newcap:true, noarg:true, trailing: true, undef:true, unused:true */
/*global Drupal: true, jQuery: true*/
/**
* File: clientside_validation_field_valdiation.js
* Version: 7.x-1.x
* Description: Replace field validation's error message placeholders with their values.
* Author: Attiks
* Language: Javascript
* Project: clientside_validation_field_valdiation
* @module clientside_validation
*/
(/** @lends Drupal */function ($) {
"use strict";
/**
* Drupal.behaviors.clientsideValidationFieldValidation.
*
* Attach behavior for replacing field validation's error message placeholders
* with their values.
*/
Drupal.behaviors.clientsideValidationFieldValidation = {
attach: function () {
$(document).bind('clientsideValidationInitialized', function(){
for (var formid in Drupal.myClientsideValidation.validators) {
if (Drupal.myClientsideValidation.validators.hasOwnProperty(formid)) {
Drupal.myClientsideValidation.validators[formid].settings.showErrors = function (errorMap, errorList) {
this.defaultShowErrors();
for (var index in errorList) {
var label = this.errorsFor( errorList[index].element );
if ( label.length ) {
label.html(label.html().replace("[value]", $(errorList[index].element).val()));
}
}
}
}
}
});
}
};
})(jQuery);
...@@ -9,31 +9,34 @@ ...@@ -9,31 +9,34 @@
function clientside_validation_field_validation_clientside_validation_form_alter(&$form, &$form_state, &$js_rules) { function clientside_validation_field_validation_clientside_validation_form_alter(&$form, &$form_state, &$js_rules) {
$field_rules = array(); $field_rules = array();
clientside_validation_field_validation_find_rules($form, $field_rules); clientside_validation_field_validation_find_rules($form, $field_rules);
foreach ($field_rules as $rule) { if (!empty($field_rules)) {
$element = &$form; $form['#attached']['js'][] = drupal_get_path('module', 'clientside_validation_field_validation') . '/clientside_validation_field_validation.js';
// Field validation 1.x foreach ($field_rules as $rule) {
if (function_exists('field_validation_get_bundle_rules')) { $element = &$form;
foreach ($rule['field']['#parents'] as $parent) { // Field validation 1.x
$element = &$element[$parent]; if (function_exists('field_validation_get_bundle_rules')) {
} foreach ($rule['field']['#parents'] as $parent) {
clientside_validation_field_validation_after_build_recurse($form['#id'], $element, $form_state, $rule['rule'], $js_rules); $element = &$element[$parent];
}
// Field validation 2.x
else {
$element = &$element[$rule['rule']['field_name']];
$field = field_info_field($rule['rule']['field_name']);
$languages = field_available_languages($rule['rule']['entity_type'], $field);
foreach ($languages as $langcode) {
if (isset($element[$langcode])) {
$element = &$element[$langcode];
}
foreach (element_children($element) as $delta) {
$element = &$element[$delta];
clientside_validation_field_validation_after_build_recurse($form['#id'], $element, $form_state, $rule['rule'], $js_rules);
} }
//Support select fields. clientside_validation_field_validation_after_build_recurse($form['#id'], $element, $form_state, $rule['rule'], $js_rules);
if (!count(element_children($element)) && isset($element['#type']) && $element['#type'] == 'select') { }
clientside_validation_field_validation_regular($form['#id'], $element, $rule['rule'], $js_rules); // Field validation 2.x
else {
$element = &$element[$rule['rule']['field_name']];
$field = field_info_field($rule['rule']['field_name']);
$languages = field_available_languages($rule['rule']['entity_type'], $field);
foreach ($languages as $langcode) {
if (isset($element[$langcode])) {
$element = &$element[$langcode];
}
foreach (element_children($element) as $delta) {
$element = &$element[$delta];
clientside_validation_field_validation_after_build_recurse($form['#id'], $element, $form_state, $rule['rule'], $js_rules);
}
//Support select fields.
if (!count(element_children($element)) && isset($element['#type']) && $element['#type'] == 'select') {
clientside_validation_field_validation_regular($form['#id'], $element, $rule['rule'], $js_rules);
}
} }
} }
} }
......
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