Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sabin Regmi 13 posts 93 karma points
    Feb 27, 2017 @ 12:04
    Sabin Regmi
    0

    jQuery validation does not work on multiple form created from same partial view. However only first form is trigger validation.

    Hi all,

    More than one forms are created on same page using for loop. First form is validated but from second one, when submit button is clicked it does not triggered to jQuery validation.

    Here is my code:

    @using (Html.BeginUmbracoForm("PostComment", "CommentController", System.Web.Mvc.FormMethod.Post, new { id = "Comment_" + answerId + "-"
    + commentParentId, @class = "Comment" }))
    {
    
    some input field
    
    <input class="" type="submit" value="Submit" id="commentBtn" />
    
    }
    
    
        <script>  
    $("#commentBtn").click(function () {
    debugger;
    var id = $(this).parent().attr("id").split('_')[1];
     $("#comment_" + id).bootstrapValidator({
                // To use feedback icons, ensure that you use Bootstrap v3.1.0 or later
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    Name: {
                        validators: {
                            notEmpty: {
                                message: 'Please Enter Your Name'
                            }
                        }
                    },
                    Comment: {
                        validators: {
                            notEmpty: {
                                message: 'Please Enter the Comment'
                            }
                        }
                    }
                }
            });
        });
    </script>
    

    There is not any error on console of browser. I am unable to understand how first form was validated but not others. Can you please suggest me any solution.

    Many Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft