I'm using hook_js_alter() in my theme template.php to load jquery 1.7 to my frontend only, and I've noticed that doing this breaks filefield uploads.

More specifically, once you select a file and click upload, the file will upload but the spinner just keeps looping. If you click preview during this, then after the refresh you'll see the link to the file and the "remove" button. If you click remove here, you'll see the same issue with the spinner continuously looping. Hit preview again, and it'll refresh with the file removed.

I tested this method with jquery 1.5.2 as well and had the same problem, so its not a jquery problem.

This problem does not exist if using the dev branch of jquery_update module to load jquery 1.7. But the issue with using this is it breaks field_ui and views functionality, so is not an option.

My code (very simple) is as follows, any ideas?

function mytheme_js_alter(&$js) {
    if (isset($js['misc/jquery.js'])) {
        $jsPath = 'https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js';
        $js['misc/jquery.js']['data'] = $jsPath;
        $js['misc/jquery.js']['version'] = '1.5.2';

Worth noting, Drupal is released with a particular version of jQuery. You generally can't add a newer version of jQuery without refactoring some core js files.


provides those core patches and more recent jQuery versions.


Try this:

function jetaatokyo_js_alter(&$javascript) {
  // Replace with current version.
  $jQuery_version = '1.5.2';
  $jQuery_cdn = 'https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js';
  $javascript['misc/jquery.js']['data'] = drupal_js_defaults($jQuery_cdn);
  $javascript['misc/jquery.js']['version'] = $jQuery_version;
  • Using drupal_js_defaults() you get 'type' => 'file' when it should be 'type' => 'external'. It is rather a compatibility problem between jQuery 1.5.2, and the JavaScript code used by Drupal.
    – apaderno
    Jun 21 '12 at 4:11
  • just tried what you suggested, but get an array to string conversion error. @kiamlaluno thats quite strange, b/c this problem doesn't arise when using jQuery Update module to laod jquery 1.5.2
    – filmoreha
    Jun 21 '12 at 4:24
  • That is because the code should eventually be $javascript['misc/jquery.js'] = drupal_js_defaults($jQuery_cdn);, but, as I said, you get wrong values for at least 'type', and 'group'. There isn't any reason to use drupal_js_defaults() because you just need to change 'type' to 'external', 'data' to 'https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js', and 'version' to '1.5.2'; the rest of the values are perfectly fine.
    – apaderno
    Jun 21 '12 at 4:35
  • Thanks for the help, in the end I couldn't come up with a solution that worked. It would seem hook_js_alter() really is only for presentational jquery. Realized this when I noticed jquery update was replacing more than just jquery and jqueryui. There is a patch out for jquery update that fixes the issues people have been having with jquery 1.7 so I am going with that.
    – filmoreha
    Jun 21 '12 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.