I may be doing something wrong, but I cannot get Ajax comments to work in Views. As an example, view the following node for the full node with comments:
http://www.repfun.com/node/184
and this one is now part of a view: http://www.repfun.com/node/185 (with full node view, and comments turned on).
Also, I seem to have to comment out:
// Drupal.attachBehaviors(html);
at tline 683, or I get a JS error. Interestingly, if no drupal-set-message occurs when the comment is posted, I do not get the error, but if it does I do get an error
| Comment | File | Size | Author |
|---|---|---|---|
| #26 | ajax-comments-multiple-per-page-743040-comment-26.patch | 1.39 KB | jon pugh |
| #8 | ajax_comments-views-patch.txt | 38.44 KB | khorpyakov |
| #7 | patch-views-ajax-comments.txt | 39.34 KB | khorpyakov |
Comments
Comment #1
mikerasmussen commentedI believe this is related to comment_bonus_api. It appears that when comments are inserted as part of a node in views, it does not end up calling the comment_bonuse_api_comment_render which means the comments are formated with something different, and that the ajax_comments_post_comment_render never gets called, and the javascript is not loaded for the ajax comments....
Comment #2
thaddeusmt commentedmikerasmussen pointed out both problems very accurately.
One of the problems is that Views directly outputs the old comments form with comment_render() in template_preprocess_views_view_row_node(). That's easy enough to fix though, just override it in the theme or the ajax_comments module and output comment_bonus_api_comment_render() instead of comment_render(). It was nice of Views to at least put this in a _preprocess_ function!
The OTHER problem is harder to solve though. Many many places in ajax_comments.js jQuery selections of "#comment-form" are hard coded. The problem is that when views outputs the comment forms there could be multiple forms, so it numbers them: "#comment-form-1", "#comment-form-2", etc. The code in ajax_comments.js doesn't detect them so the forms aren't "ajaxified".
I'm not sure how to solve this though. I thought at first I could just change the selector to a wildcard ("[id^=comment-form]" instead of "#comment-form"). This worked for me because I am using Views to just show one node - I don't have multiple comment forms. But if you DID have multiple comment forms, it wouldn't work. You could post from any comment form, but the new comments would appear in the first comments area and all of the ajax stuff like "reply" and "edit" won't work.
Any ideas on how to deal with the dynamic form IDs?
I guess we could do a "foreach" thing and pass in the right form ID as an extra parameter during all of the binds, but that's a bit of refactoring I'm not looking forward to.
Any other ideas?
Comment #3
that0n3guy commentedsub...
Comment #5
bflora commentedSubscribing.
Comment #6
rjbrown99 commentedIs this related to or a duplicate of this issue? #771298: Using drupal_add_js() for settings in hook_form_alter() breaks on node Views
Comment #7
khorpyakov commentedThis is a really huge modification (possibly big enought to be a separate version) which fixes ajax_comments compability with views. Almost all the javascript code is rewritten. Fixed comment form id's are replaced with variable id's, allowing multiply forms on the same page.
Comment #8
khorpyakov commentedRemoved debug code from the patch above.
Comment #9
jcisio commentedThere is some unrelated files in the patch (like .project), unnecessary coding standards fixes (or introduced problems). Could you submit a new patch with only necessary changes? It's hard to review.
Comment #10
jamesdixon commentedkhorpyakov this patch is exactly what I'm looking for! I started trying to make the edits you made yourself to get this going with views and multiple comment streams, but my novice javascript skills are holding me back. Then I found this, which is awesome, good job!
Would you mind sending me your patched version, or pointing me in the direction of where I can find the code version you ran the patch on? Was it from CVS revision revision 1.1.2.39? Sorry I'm kind of a noob with patch files, I tried running it on 6.x-1.x-dev but it's been updated since your patch and the effects didn't work.
Comment #11
jamesdixon commentedI found the version you patched, and am having difficulties getting it working. It seems like all the form elements are getting processed as they're getting the ajax-processed and ahah-processed classes, but none of the html updates or effects are working. After adding a comment and refreshing the page, the comment appears, so its' kind of working.
Using firebug, I can tell that when I click on "Save" ajax_comments_show_progress isn't getting called. How can I tell if the form elements are getting their functions bound to them properly in Drupal.ajax_comments_init_form?
I also noticed a small bug in the patch at the top of ajax_comments_form_comment_form_alter() in ajax_comments.module:
There were two comment-form-1's being generated with views and multiple comment forms so I updated my code to this:
Comment #12
doublejosh commentedAny desire to alter the form ID for multiple forms on a page?
I have the same issue with comments in views. Perhaps that form could use the cid?
Comment #13
doublejosh commentedNoticed that fortunately the comment is only displayed as having been submitted to both threads.
After a page refresh the comment is only present in the correct node thread. (D7, not sure about D6.)
Comment #14
nigma3d commentedthe patch works great, except for when the comment is submitted, the comment doesn't display and refresh via ajax, you have to reload the page to see the comment -- after really digging, it apparently doesn't get the nid or form_num information from ajax, most particularly the function jQuery.fn.ajaxCommentsSubmitToggle
it fails on the link variable when trying to look through the html var. Dumping the variables show that obj and html work just fine, it just fails on the link variable thus the remainder of the script doesn't work properly. Hardcoding var form_num and var nid for testing makes the script work perfectly (which obviously isn't a solution.
Any idea how to rectify it? I am very inexperienced with jquery.
Comment #15
nigma3d commentedactually, found the problem. Changing
to this:
Makes this patch work just fine!
Comment #16
lewie6 commentedplease can someone post a download to the patched module?
or add the code to a dev release?
Comment #17
Berliner-dupe commentedWhen i patch ajax_comment with patch from #8 over Cygwin (windows) i get errors
Hunk #1 FAILED at 110.
Hunk #2 FAILED at 142.
Hunk #1 FAILED at 157.
Hunk #1 FAILED at 167.
Can anyone help me?
Comment #18
El Capitan commented#17, try commit d674cb9574de6c487c161c6fc2d838cad7f5237f from GIT repo, this should be patchable....
Comment #19
SlayJay commentedIs there a patch for D7? running into this exact same problem. Need to show a view of comments with ajax functionality.
Comment #20
SlayJay commentedFYI, this may be completely unrelated, but I wanted to put it out there in case anyone else runs into this problem.
In D7, if you're trying to make a view of nodes with an ajax pager, and those nodes are embedding a view of comments in their TPL file, and you're using ajax comments... what happens is the ajax comments will work for each of the embedded views, but the main outer view of nodes will have it's ajax functionality broken.
Commenting out the following lines in ajax_comments.module fixes this, with (seemingly) no side effects to ajax comments functionality... at least to my install:
Hope this helps someone!
Comment #22
kmajzlik commentedThis works for me in Drupal 7:
template.php:
ajax_comments.module line 231:
Comment #25
Bitvark commented#22 works for me too on D7.
Thanks
Comment #26
jon pughAttached is a patch file with the code from #22, but with ajax_comments_preprocess_comment_wrapper()
Tested on node pages too, works great.
Comment #28
IWasBornToWin commentedIs the latest patch in d7 download? I just installed and am having same issue....having to reload page to see comment
Comment #29
tevih commentedHaving same issue - is this slated to be released?
Comment #30
adamgerthel commented#26 fixed our issues
Update: It doesn't work together with view ajax pager
Update 2: It does work with ajax pager, just not Views Load More module
Comment #31
acouch commentedMarking this as duplicate: #1511726: Multiple Panels comments append to top of page, not pane
Comment #32
heretic381 commentedIt works, except for the option if you dont want the reply form to be open by default. When you click on "add new comment" link, nothing happens.
Maybe few more lines for that to work?
Comment #33
nikkubhai commentednot a duplicate...the other issue is related to panels.
Comment #34
nikkubhai commentedmarked http://drupal.org/node/1711476 as duplicate of this
Comment #35
grasmash commentedI created a completely separate patch for a views "add comment" field here: #1711476: Views integration
It does not modify the module's javascript at all.
Comment #36
mstef commentedThe problem I'm having is how ajax_comments adds markup to the #prefix and #suffix of comments in hook_comment_view_alter(). It adds numerous open and closed DIV tags, which screw up the layout since Views outputs rows as DIVs. Any one else experiencing that?
This seems only get messed up when we're dealing with comments that have a parent comment.
I'm seeing some #prefix that contain two divs, a close and an open div. Some #suffix contain two closed divs, etc. There's no way that this won't break views, if you're using the Comment display.
To get indenting working with comments, I've been using this:
Obviously you need to be using the comment:thread sort (ascending), or you'll have to update your hook.
So, I think ajax_comments needs to handle indenting/wrapping with each individual comment, and stop trying to group them together with DIVs using prefix/suffix.
Comment #37
mstef commentedThe reason why the ajax_comment indenting isn't working is because it's applying the class tag twice to the wrapper in ajax_comments_comment_alter() (line 377). You end up with:
Here's the issue: #1792734: Indentation fix for threaded comments
Comment #38
mstef commentedAll of the indenting should probably take place at the end of hook_comment_view_alter(). Instead of nesting each level together, just indent each comment by itself, based on how deep it is:
And get rid of the $comment->wrappers_to_close, etc...
Comment #39
Heihachi88 commented#15 (nigma3d) Are you doing that on drupal 6? Because i changed that line but still it doesn't refresh automatically. I have to reload the page to see a new comment.
Comment #40
ashwinsh#22 works for me too on D7.
Thanks
Comment #41
socialnicheguru commentedcan #22 be rerolled? it doesn't apply anymore
patch -p1 < ajax-comments-multiple-per-page-743040-comment-26.patch
Comment #42
muschpusch commentedThere is views integration but i don't think it's coming from this issue...
Comment #43
formatC'vt commentedfixed in latest dev