My template looks like :
{% for comment in service.comments.all %}
{{comment.comment}} -- commented by {{comment.user}}<br/>
<div id="comment-reply">
`{% for reply in comment.comment_replies.all %}`
<p>{{reply.comment_reply}} -- replied by {{reply.user}}</p><br/>
{% endfor %}
</div>
<a class="myClick" href="#">Reply</a><br/>
<form class="comment-replyform" action="some_url" method="post" style="display: none;">{% csrf_token %}
{{ comment_reply_form.as_p }}
<input type="submit" name="submit" value="Reply">
</form>
{% empty %}
No comments
{% endfor %}
Here I have comment replies for comment.
My comments and comment replies are listing properly.
Here What I want is when I click on Click I want to display the comment reply form, which is displaying fine..
My jquery looks like :
$(".myClick").click(function(event){
event.preventDefault();
$(".comment-replyform").show();
$(".myClick").hide();
})
$('.comment-replyform').on('submit', function(event){
event.preventDefault();
$.ajax({
url: $(this).attr('action'),
type: $(this).attr('method'),
data: $(this).serialize(),
success: function(response) {
$('#id_comment_reply').val('');
$('#comment-reply').append("<p>"+response.comment_reply+" -- "+"replied by "+ response.user+"</p><br/>")
}
});
})
The problem is when I click on Click, it displays all the form for comment replies but I want only the form to be shown where I click
Another thing is when I submit the first form it works well but when I submit second or third form... The value is shown on the first div. I mean the comment reply for second form is appended to first.
How can I solve this ?