I have a view of node teasers. I have added custom form to every teaser. Form is submitted via Ajax (in theory).
Code for submit button:

$form['my_module_form']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Send'),
    '#ajax' => array(
      'callback' => 'my_module_form_ajax_callback',
    ),
  );

Form is added in hook_node_view like:

$content['my_module_form'] = drupal_get_form('my_module_form', $node);

Anyway after loading content by autopager ajax event isn't attached to any of new forms.

I looked to the views_infinite_scroll.js and events are attached:

Drupal.attachBehaviors(this);

but it doesn't work in my case.

AHAH works like expected on content loaded via normal page refresh

Comments

codium’s picture

Issue summary: View changes
codium’s picture

Priority: Normal » Major
organicwire’s picture

I have a similar problem when loading nodes which have javascript code embedded. The JS code won't be executed when loading via Views Infinite Scroll. The problem is that the JS code is stripped away.

Views Infinite Scroll uses the outdated jQuery plugin jquery.autopager (which is quite unmaintained since 2009). The plugin strips away all javascript from the content it loads. See the following code:

// in jquery.autopager-1.0.0.js, line 139ff.
function insertContent(res) {
	var _options = options, 
		nextPage = $('<div/>').append(res.replace(/<script(.|\s)*?\/script>/g, "")),

There is an attempts to solve this in #2122273 (using a library without a full open source license).

Another good way to solve this would be to provide a JS callback when loading finished in jquery.autopager.

organicwire’s picture

Title: AHAH form doesn't work after paging » Javascript / AHAH doesn't work after paging

As described in #3 not only AHAH forms but any JS code is affected. Therefore I'm changing the issue title.

pacome’s picture

Status: Needs review » Active

Hello

I have the same problem with an imagefield using slideshow formater in the view, the first page loads correctly the slideshows, while the next pages don't.
Can anyone give some help with that ? I would be happy to give a hand with some testing.

I changed the issue status to "active" as it looks to still be the case.

-P-

pacome’s picture

i tried the option in #2122273 with the other library, maybe i missed something, but it doesn't solve the question in my case.
The callback looks to be the one, unfortunately i'm not able to write it.. if someone could help with it that would be a great improvement !

pix_’s picture

I've successfully implemented views infinite scroll with AHAH behaviours applied to new scrolled elements. It was a durpalcommerce site and the "add to cart" was handled by ajax. This is what i've done:

1) I'm using a slightly modified version of jquery.autopager-1.0.0.js, mostly because an issue with search api, which can be found here: https://github.com/agavee/jquery-autopager-searchapi.
2) I'm manually re-adding to Drupal.settings.ajax what was stripped away, as suggested in #3, listening on a ajaxSuccess(). Here an example of the code i'm using:

 $(document).ajaxSuccess(function (event, xhr, settings) {

    // results from scrolling a product page
    res = xhr.responseText;
    res = res.replace(/<script\s(.|\s)*?\/script>/g, "");

    if (res) {
      res = $('<div/>').append(res);
      $('article.productitem.views-row', res).each(function () {
        var id = $('.form-submit', this).attr('id');
        Drupal.settings.ajax[id] = {
          "callback": "_mndv_cart_add_product_ajax_callback",
          "progress": {"type": ""},
          "effect": "none",
          "event": "mousedown",
          "keypress": true,
          "prevent": "click",
          "url": "/system/ajax",
          "submit": {
            "_triggering_element_name": "op",
            "_triggering_element_value": Drupal.t("Add to cart")
          }
        };
      });
      
      Drupal.attachBehaviors();
    }
  });

Hope it helps.

alejomc’s picture

Same issue for 7.x-2.x version

honza pobořil’s picture

Status: Active » Closed (outdated)

7.x-1.x will receive no work. Migrate to 7.x-2.x.