I have something like wall on facebook. Every post has some comments below. What I am trying to do is editing comment option. It replaces the current comment with textarea form and after accept shows the new comment. The button did not work very well. It should be dynamic (working without refreshing the website). However I had some difficulties. The edit link was opening textarea under some other comments or was showing the first comment in textarea box (the new one should appear...) What I am trying to do now is to pin the .data() to "this" button and it will contain the new comment text so i will be able to read it dynamically to the opening textarea. I am not absolutely sure about what I am doing, and I am not sure about using of .this but I hope you will help me out somehow guys! The alert shows "unknown data". Is there maybe any better solution that do not require master level skills in js?
<a href="#!" class="editButton" onClick="editComment({{$comment->h_id}}, `{{$comment->f_text}}`)">
<script>
function editComment(id, text){
var thisId = "#" + id;
$(thisId).replaceWith("<form class='newCommentForm'>\n\
<textarea id='newComment'>" + text + "</textarea>\n\
<input type='button' id='submit' value='save'>\n\
</form>");
$('#submit').click(function() {
var newComment = document.getElementById('newComment').value;
$.ajax({
type: 'get',
url: '/editcomment',
data: {newComment: newComment,
id: id},
success:function(){
$(".newCommentForm").replaceWith("<span id='" + id + "' class='limitedText shorter' style>" + newComment + "</span>");
$(".editButton", this).data("PinComment", "newComment");
alert($(".editButton", this).data("PinComment"));
},
error:function(){
alert('error');
}
});
});
}
</script>
laravel php laravel 5 laravel 4 laravel with laravel tutorial
Aucun commentaire:
Enregistrer un commentaire