0

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>
Hal
  • 981
  • 1
  • 9
  • 22
koichi_n
  • 107
  • 1
  • 1
  • 9
  • Can you copy in any Javascript errors you're getting from your browser's error console? Press F12 in Chrome or Firefox with Firebug installed. Ctrl-Shift-J will get you there in Firefox sans Firebug. – Hal Jan 10 '12 at 08:13
  • @harrison_m Thanks, I got "show_reply_form is not defined" at error console. – koichi_n Jan 10 '12 at 09:14

1 Answers1

0

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.

Sandeep
  • 819
  • 10
  • 16