Question

I'm going to use django-threadedcomments library at my Django project.
https://github.com/HonzaKral/django-threadedcomments

The tutorial gives sample code, including Javascript to reply to comments in threaded-comment style.
I've tried to test this sample, and the library works itself but the Javascript to reply to comments doesn't work.
And there's nothing wrong with jQuery loading or with Django static files loading.

This is the tutorial. http://goo.gl/vyFw9

I'm wondering:
1)Is there anything wrong with the script?
2)If not, any ideas as to why this doesn't work?

function show_reply_form(comment_id, url, person_name) {
var comment_reply = $('#' + comment_id);
var to_add = $( new Array(
'<div class="response"><p>Reply to ' + person_name + ':</p>',
'<form method="POST" action="' + url + '">',
'<ul>',  '{{ form.as_ul|oneline }}',
'<li><input type="submit" value="Submit Comment" /></li>',
'</ul>', '</form>', '</div>').join(''));
to_add.css("display", "none");
comment_reply.after(to_add);
to_add.slideDown(function() {
    comment_reply.replaceWith(new Array('<a id="',
    comment_id,'" href="javascript:hide_reply_form(\'',
    comment_id, '\',\'', url, '\',\'', person_name,
    '\')">Stop Replying</a>').join(''));
});
}
function hide_reply_form(comment_id, url, person_name) {
var comment_reply = $('#' + comment_id);
comment_reply.next().slideUp(function (){
    comment_reply.next('.response').remove();
    comment_reply.replaceWith(new Array('<a id="',
    comment_id,'" href="javascript:show_reply_form(\'',
    comment_id, '\',\'', url, '\',\'', person_name,
    '\')">Reply</a>').join(''));
});
}

<a id="c{{ comment.id }}" href="javascript:show_reply_form('c{{ comment.id }}','{% get_free_comment_url post comment %}','{{ comment.name }}')">Reply</a>
Was it helpful?

Solution

First thing I see is that you are not appending to_add to the document at all, i.e something like $('#someExistingDiv').append(to_add);

After creating the to_add, it has to be added to the DOM. I don't think there are any JS errors. I'm pretty sure it you are just not seeing the new comment element created.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top