Here is the setup:

  • We're using the Views pager (with AJAX) to create a node-slideshow - so pager is set to show one node (slide) at a time
  • On each node load we have the comments block module in place and it reloads with that particular node's comments.
  • The comments form is set to use AJAX for submission (so users stay on the same slide instead of redirecting to the node page with standard comments behavior)
  • Views AJAX History "eats" the comment form submission because it uses AJAX and then the comment is never submitted

I'm trying to find a way to exclude non-Views AJAX calls from Views AJAX History - even explicitly exclude the comments form ones - but this JS is a bit over my head. Any pointers?

Comments

nod_’s picture

Category: support » bug

To fix this a check needs to be added somehow in Drupal.ajax.prototype.beforeSerialize and Drupal.ajax.prototype.beforeSubmit to check that the ajax call was throught Views and not some other AJAX call on the page.

Are you using custom code or a module to submit the comments with ajax?

(hopefully i'll have time tonight to see which checks can be made).

sokrplare’s picture

Wow, you're fast! We are using custom code for the AJAX comments so I'll see if I can add it in there. No guarantees I'll be able to figure it out, but will do my best effort - thanks!

sokrplare’s picture

Brilliant!

I wrapped everything inside Drupal.ajax.prototype.beforeSerialize and Drupal.ajax.prototype.beforeSubmit with:
if(options.url.substring(0, 11) == '/views/ajax') { ... }

Another (better?) option would be checking against if options.data.view_name is set? It works for me so I'm content, but you'd know best what to check against for widest support.

sokrplare’s picture

For reference, here are screenshots of what the arguments from comment form AJAX submissions are.

nod_’s picture

data.view_name does sounds like a good idea, do you have a patch laying around? :)

sokrplare’s picture

Nope, but I sure can! Will attach it here in the next couple days.

nod_’s picture

Awesome, thanks :)

sokrplare’s picture

Status: Active » Needs review
StatusFileSize
new2.86 KB

My patch files never seem to work, but hoping for the best here!

nod_’s picture

Status: Needs review » Needs work

Applied properly for me :)

A couple of things:
1) you need to leave beforeSubmit.apply() and beforeSerialize.apply() out of the if, because they need to run on every requests. Otherwise we'll break something else :)
2) you can check with if (option.data.view_name) {} it should be enough.

Thanks a lot for actually providing the patch :)

sokrplare’s picture

Not working on the part of the project using this anymore, but wanted to get a patch file your way with these two changes made - haven't got to test this, but so long as you're right about the things you listed above, these are the only changes made, so should be good! Thanks, _nod.

sokrplare’s picture

Status: Needs work » Needs review

Hey nod_ I'm back doing a third migration to Drupal for the same client, any chance this patch will get committed? Thanks!

nod_’s picture

Status: Needs review » Fixed

Sorry that was actually applied on my local sandbox forgot to push and commit at the time. Fixed, thanks for the patch!

sokrplare’s picture

Woohoo!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.