0

We are using the popup module to render views within a page.

One of the views has a file field for uploading. The popup module can render the popup as part of the page and then display the popup or pull the data in through an ajax call.

If the views is pulled in as part of the rendering of the page, the field has ajax enabled and works correctly.

However, when the view is pulled in through ajax, the field does not have ajax enabled and fails to function.

There are dozens of such popups on the page and it is simply not practical to have all the popups pre-rendered (not to mention the inefficiency of it).

I have tried pulling in just one popup to check whether its just some missing javascript files but while the solitary popup works as expected, the other ones still fail to function.

Digging into the popup module, the bit of code to retrieve the view is exactly the same regardless of whether it's being pulled in as part of the page, or separately through ajax.

from popup.api.inc

function _popup_view($attributes, $return = FALSE){

  $title = FALSE;
  $body = FALSE;

  if (module_exists('views')){

    $view = views_get_view($attributes['view']);

    $display = $attributes['display'] ? $attributes['display'] : 'default';
    $args = isset($attributes['args'])
      ? explode(',', $attributes['args'])
      : array();

    if ($view){
      $view->set_arguments($args);
      $view->set_display($display);
      $body = $view->preview();

      $computed_title = $view->get_title();
      $title = $attributes['title']
        ? $attributes['title']
        : ($computed_title
            ? $computed_title
            : @$view->display[$display]->display_options['title']
          );

    }

  } else {
    $body = false;
  }

  $title = $title ? $title : 'View';
  if ($return == 'title'){
    return $title;
  }

  if ($return == 'body'){
    return $body;
  }

  return
    popup_element(
      $title,
      $body,
      $attributes
    );

}

The relevant javascript section:

  var placeContent = function(data, destination){

    thisObject.body.unbind('showing', fetchContent);
    var close = $('.popup-close-button', destination);

    if (close.length){
      close.siblings().remove();
      destination.append(data);
    } else {
      destination.html(data);
    }

    Drupal.attachBehaviors(destination);
  }

The popup module has a mechanism for rendering drupal forms view a popup and load that via ajax as well. This too does not work.

I should state that regular forms do work without any issues. I have views being rendered via ajax popup that have other controls (submit buttons just now) which work without any issues.

However, if I add a file form field into any of those forms, it breaks even the original controls. I believe this may be related to the form changing to a multipart mime form.

This leads me to the conclusion that there is something specific about the file form field that fails when being retrieved through ajax.

Manually adding the file.js has had not impact (I was thinking that attachBehaviours may not be working correctly)

Any help to resolve this will be greatly appreciated.

1 Answer 1

0

Turns out it was a bug in the popup module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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