I have a form that is being created inside a v-for and I need to submit a form being created like below but nothing is working. I have used Ajax and Axios all work fine if the form is outside the v-for loop. Can anyone propose a way to go about it. Code below:
<div id="classPosts">
<div class="panel panel-default" v-for="single_post in class_posts">
<div class="panel-body">
<div id="responseDiv">
<div class="collapse" :id="`comment_div_${single_post.id}`">
<p></p>
<br>
<form action="#" method="post">
<div class="row" id="comment_div" style="padding-left:20px;padding-right:20px;">
<input type="hidden" name="post_id" id="post_id" :value="`${single_post.id}`">
<input type="hidden" name="user_id" id="user_id" :value="`${single_post.userid}`">
<div class="col-sm-10">
<textarea name="post_comment" id="post_comment" rows="2" style="margin-left: 0px;resize: none;" class="form-control" placeholder="Reply" required v-model="post_comment"></textarea>
</div>
<div class="col-sm-2">
<button class="btn btn-primary pull-right" id="submitComment" name="submitComment" @click="createComment()">Comment Post</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
The above is where the form is being dynamically created: - : And below is the Vue instance. When I click on Comment Post button, nothing happens and even the alert("The Create comment function has been summoned."); does not show.
<script type="text/javascript">
new Vue({
el: '#classPosts',
data: {
post_comment: '',
class_posts: []
},
methods: {
loadData: function() {
...
},
createComment: function() {
alert("The Create comment function has been summoned.");
},
mounted: function() {
this.loadData();
setInterval(function() {
this.loadData();
}.bind(this), 60000);
}
});
Below is the console.log for class_posts. Return value.
