Jump to:
| Project: | AJAX Comments |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | major |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
When the user clicks 'save' and then while is the comment is being saved, clicks reply to another comment, the previous comment gets saved as a reply to this one.
To reproduce:
1. Write a comment
2. Click save
3. While the comment is not yet saved, click reply to another comment.
4. You will see the comment being popped into the incorrect thread.
I looked into the JS code and found out that the click to reply handler does the job of assigning the comment number. This function does not check whether a comment save is still in progress.
Since I am a newbie in AJAX and know almost nothing about this module, I was not sure what to put in there to fix. This problem definitely needs to be fixed. It affects slower sites really badly.
Comments
#1
The following function in ajax_comments.js should return before setting the pid if the comment is still being saved
/*** Helper function for reply handler.
*
* In addition to clearing the textareas and forms, this is where the PID value
* is set for the comment. The PID controls whether this is a new standalone
* 'anchor' comment or a reply to an existing comment thread. A PID value
* of 0 is a new anchor comment while any other number is a reply.
*
* @param $pid
* Some comments are replies to other comments. In those cases, $pid is the parent comment's cid.
* @param $rows
*
*/
function ajax_comments_rewind(pid, rows){
// Return if the comment is being saved.
#2
What does this code fragment do? There is no variable named 'submitted'! Or is there?
// Add sending on Ctrl+Enter.if ((e.ctrlKey) && ((e.keyCode == 0xA) || (e.keyCode == 0xD)) && !submitted) {
submitted = true;
$('#ajax-comments-submit').click()
}
#3
I tried. It does not work. Takes me to a new page.
if(submitted) return;#5
Any update on this?
#6
Shouldn't we remove the reply handlers as well?
/*** Comment submit routine.
*/
function ajax_comments_submit($form, &$form_state) {
//remove self
unset($form_state['submit_handlers']);
// ..and standart comments submit handler
foreach ($form['#submit'] as $key => $value) {
if ($value == 'comment_form_submit') {
unset($form['#submit'][$key]);
}
}
//execute all others
form_execute_handlers('submit', $form, $form_state);
#7
How do I know if the comment is being saved now?
/*** Reply links handler.
*
* This function is called as the handler to the .click() event. The events were bound
* during the init functions above. This is the function executed when the user clicks
* on a 'reply' button on the page or the 'Post new comment' link.
*/
Drupal.ajax_comments_reply_click = function() {
// We should only handle non pressed links.
if (!$(this).is('.pressed')){
action = $(this).attr('href');
form_action = $('#comment-form').attr('action');
link_cid = ajax_comments_get_cid_from_href(action);
rows = Drupal.settings.ajax_comments_rows_default;
if ($('#comment-form-content').attr('cid') != link_cid) {