So, I've browsed many threads on SO, but couldnt find my related query. Well, I've a webapp similar to SO, where questions are asked, and people have the liberty to comment/answer on the question (also comments on answers are allowed).
I get the Answers
of a particular question via the API and form the respective HTML and append it to a div. My HTML is somewhat like this:-
<div>
<p> Some Answer </p>
<div class="comments"></div>
<form id="form_62" class="comment_form" method="POST" action="URL"> <!--This id is variable-->
<textarea rows="3" name="comment"></textarea>
<button type="submit">Comment </button>
</form>
</div>
</div>
So, I append HTML like this in some div DYNAMICALLY. As you can see, there can be many answers, and hence multiple comments
form.
I wrote a validator against it, which is as follow:-
$(function(){
$(document).on('submit', '.comment_form', function(e){
alert(111)
form_id = $(this).id
e.preventDefault();
if($(this).valid()){
$.ajax({
...
});
}
})
$(this).validate({
ignore: '',
onsubmit : false,
rules: {
comment: {
required: true,
minlength: 10
}
}
});
})
This does not works as expected.
So, my question is how can I validate my current form which is submitted?