I have a problem with my comment system on the website.
The problem is this, I want the comments to be edited in a modal window "that already works thanks to bootstrap" but I can not get that comment that will be edited to load in the modal window.
This is my code:
HTML:
<article class="row">
<div class="col-md-3 col-sm-3 hidden-xs">
<figure class="thumbnail">
<img class="img-responsive" src="/uploads/avatars/{{ $comment->user->profilepic }}" />
<figcaption class="text-center">{{ $comment->user->name }}</figcaption>
</figure>
</div>
<div class="col-md-8 col-sm-8">
<div class="panel panel-default arrow left">
<div class="panel-body">
<header class="text-left">
<div class="comment-user"><i class="fa fa-user"></i> {{ $comment->user->name }}</div>
<time class="comment-date" datetime="{{ $comment->created_at->diffForHumans() }}"><i class="fa fa-clock-o"></i> {{ $comment->created_at->diffForHumans() }}</time>
</header>
<div id="comment-post">
<p id="display-post">{{ $comment->comment }}</p>
</div>
</div>
<div class="panel-footer list-inline comment-footer">
@if(Auth::guest())
No puedes responder ningún comentario si no has ingresado.
@else
@if(Auth::user() == $comment->user)
<a href="#" data-toggle="modal" data-target="edit-comment" class="edit-comment">Editar</a> <a href="#" data-toggle="modal" data-target="delete-comment" class="delete-comment">Eliminar</a>
@endif
@if(Auth::user() != $comment->user)
<a href="#">Responder</a>
@endif
@endif
</div>
</div>
</div>
</article>
JS:
$('.edit-comment').click(function(event){
event.preventDefault();
var commentBody = event.target.parentNode.childNodes[2].textContent;
$('#comment-body').val(commentBody);
$('#edit-comment').modal();
});
What I want is that when you click on edit in any comment, open the modal and load in the comment that will be edited. In this case:
{{ $comment->comment }}
I've tried more than that of parentNode
and childNodes
but every time I open the modal "click edit" load empty spaces, or load the name of the user who made the comment and the date of creation, or load " edit - delete "< - (the buttons) or just load everything" depending on the value you place in childNodes
I have occurred to place several times parentNode
but nothing goes the same.