Scenario:

Page displays two entities, each with a yes/no rate widget. A "Load more" button is clicked, which triggers an AJAX event that loads two more entities with their own rate widgets. Voting in any of the four widgets now causes an error (image1).

Cause:

The module expects Drupal.settings.rate.basePath to be a string, but due to the cumulative nature of drupal_add_js(), it becomes an array after the AJAX call. (image2)

Errors:

Some errors that I have seen result from this are:

TypeError: Drupal.settings.rate.basePath.match is not a function

Uncaught TypeError: undefined is not a function

Uncaught TypeError: Object [object Array] has no method 'match'

Comments

yuriy.babenko’s picture

Issue summary: View changes

fixed typo

yuriy.babenko’s picture

StatusFileSize
new1.25 KB

After reading through https://drupal.org/node/208611, https://drupal.org/node/1875632, and https://drupal.org/node/1911578, I'm thinking this is a Drupal core issue, not Rate specifically.

I've attached a workaround patch. It's ugly, but it works.

yuriy.babenko’s picture

Issue summary: View changes

fixed typo

rooby’s picture

Version: 7.x-1.6 » 7.x-1.7
Issue summary: View changes
Status: Active » Needs review

I have had issues with this module and the https://www.drupal.org/project/views_load_more ajax views paging and this patch resolves the issue for me

rooby’s picture

Issue summary: View changes
rooby’s picture

Issue summary: View changes
rooby’s picture

StatusFileSize
new1.1 KB

Here is an updated patch with no code changes.

Just rerolled to apply cleanly to the latest dev version of the module with patch -p1.

Anonymous’s picture

The patch fixes my issue with views load more, also tested with pager options with ajax, works great. Thanks @rooby and @yuriy

jrabeemer’s picture

This patch works. But after a few rate button clicks after an AJAX refresh, I get multiple progress icons that stack exponentially per rate button click. Sorry but I can't tell if this is within the scope of this bug or not.

$(document).bind('eventAfterRate', function(event, data) { // trigger an ajax refresh after an rate button click.
  $(obj).closest('.view').triggerHandler('RefreshView'); // trigger an ajax refresh of the view. however, the rate button inside the view after the AJAX refresh begins to stack on every click.
});
Fidelix’s picture

It worked flawlessly for me, and I'm doing a bunch of complex ajax stuff with the comments.

quotesbro’s picture

#1 worked for me too, thanks Yuriy.

ivnish’s picture

Status: Needs review » Closed (outdated)

Drupal 7 is EOL. Issue will be closed, but patches are still here

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.