Posted by mikerasmussen on March 15, 2010 at 5:25pm
26 followers
| Project: | AJAX Comments |
| Version: | 7.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | major |
| Assigned: | Jon Pugh |
| Status: | closed (duplicate) |
Issue Summary
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
Comments
#1
I 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....
#2
mikerasmussen 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?
#3
sub...
#5
Subscribing.
#6
Is this related to or a duplicate of this issue? #771298: Using drupal_add_js() for settings in hook_form_alter() breaks on node Views
#7
This 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.
#8
Removed debug code from the patch above.
#9
There 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.
#10
khorpyakov 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.
#11
I 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:
<?phpfunction ajax_comments_form_comment_form_alter(&$form, $form_state) {
// Add class for multiply comments form selection
$form['#attributes']['class'] = 'comment-form';
// Change form id for single/multiply comment form processing
if ($form['#id'] == 'comment-form') {
$form['#id'] = 'comment-form-1';
$form_num = 1;
} else {
$dash_number = substr($form['#id'], strrpos($form['#id'], '-'));
$stripped_number = substr($dash_number, 1);
$form_num = $stripped_number + 1;
}
...
?>
#12
Any 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?
#13
Noticed 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.)
#14
the 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
var obj = $(this[0]);var html = obj.html();
var link = obj.find('a[href*=/comment/reply]');
var form_num = ajax_comments_get_form_num_from_href(link.attr('href'));
var nid = ajax_comments_get_nid_from_href(link.attr('href'));
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.
#15
actually, found the problem. Changing
var link = obj.find('a[href*=/comment/reply]');to this:
var link = $(this[0]).find('.comment_reply a').attr('href');Makes this patch work just fine!
#16
please can someone post a download to the patched module?
or add the code to a dev release?
#17
When 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?
#18
#17, try commit d674cb9574de6c487c161c6fc2d838cad7f5237f from GIT repo, this should be patchable....
#19
Is there a patch for D7? running into this exact same problem. Need to show a view of comments with ajax functionality.
#20
FYI, 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:
<?php// add 'new' anchor if needed
if (!empty($comment->first_new)) {
$prefix .= "<a id=\"new\"></a>\n";
}
?>
Hope this helps someone!
#22
This works for me in Drupal 7:
template.php:
<?phpfunction THEME_preprocess_comment_wrapper(&$variables) {
$variables['content']['comments']['#prefix'] = '<div id="comments-wrapper-nid-' . $variables['node']->nid . '">';
$variables['content']['comments']['#suffix'] = '</div>';
}
?>
ajax_comments.module line 231:
<?php$commands[] = ajax_command_append('#comments-wrapper-nid-' . $form_state['values']['nid'], $notify_text . $comment_output);
?>
#25
#22 works for me too on D7.
Thanks
#26
Attached is a patch file with the code from #22, but with ajax_comments_preprocess_comment_wrapper()
Tested on node pages too, works great.
#28
Is the latest patch in d7 download? I just installed and am having same issue....having to reload page to see comment
#29
Having same issue - is this slated to be released?
#30
#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
#31
Marking this as duplicate: #1511726: Multiple Panels/Views comments append to top of page, not pane or view
#32
It 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?