Closed (fixed)
Project:
Clientside Validation
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
10 Apr 2013 at 16:32 UTC
Updated:
16 Sep 2013 at 09:31 UTC
I was using the Advanced Aggregation module, and found a small bug in the implementation of hook_add_js(): it does not use the $javascript as a reference, so the JavaScript is never added when the Advanced Aggregation is enabled.
The correct implementation should be:
/**
* Implements hook_js_alter().
*/
function clientside_validation_js_alter(&$javascript) {
$clientside_validation_settings = &drupal_static('clientside_validation_settings', array());
if (isset($clientside_validation_settings['clientsideValidation'])) {
foreach ($clientside_validation_settings['clientsideValidation']['forms'] as $form_id => $settings) {
$stripped_form_id = $form_id;
$matches = array();
preg_match(' /.*?(--(\d)*)/', $form_id, $matches);
if (isset($matches[1])) {
$stripped_form_id = str_replace($matches[1], '', $form_id);
}
if ($stripped_form_id != $form_id) {
$clientside_validation_settings['clientsideValidation']['forms'][$form_id] = $clientside_validation_settings['clientsideValidation']['forms'][$stripped_form_id];
$clientside_validation_settings['clientsideValidation']['groups'][$form_id] = $clientside_validation_settings['clientsideValidation']['groups'][$stripped_form_id];
}
}
}
$javascript = drupal_add_js($clientside_validation_settings, 'setting');
}
Comments
Comment #1
attiks commentedCan you provide a patch?
Comment #2
adam_bearYep... this function is buggy. In addition to the missing $js param, it needs to be assigned to the module js group.
$clientside_validation_settings['clientsideValidation']['group'] = JS_DEFAULTComment #3
amberau79 commentedNote that implementing this way also fixes a bug where the settings were stripped if the scope of the js settings was set to footer. Thank you!!
Comment #4
jelle_sFixed in the latest dev version. Thanks for the report
Comment #6
vflirt commentedHi,
i have to reopen this because this is actually breaking the locale js. If you look at the locale_js_alter you will see that it adds the translation javascript file but because you overwrite the javascript array you are actually removing this. You should only add your things and/or edit current records in the array. Changing all the javascript array is just breaking th site js and therefor you are not getting any javascript translations so Drupal.t() will not work at all.
What I think should be done is :
$javascript['settings']['data'][] = $clientside_validation_settings;instead of
$javascript = drupal_add_js($clientside_validation_settings, 'setting');This way only the needed settings are added to the javsacript array that will be compressed later on.
Hope someone else could trow a thought on this.
Kind Regards
Comment #7
jelle_s#6 is fixed in the latest dev version.