How to correctly validate a modal form

前端 未结 3 559
南笙
南笙 2020-12-09 11:42

I can\'t seem to get validation to work on my bootstrap modal, I have struggled with several of the examples that I have encountered.

What is the correct way to vali

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 12:09

    You have two issues:

    1. You're button needs to be set to type="submit" not type="button"

    2. Your submit button should be inside your form tag.

    See working example Snippet.

    $(function() {
    
      $("#newModalForm").validate({
        rules: {
          pName: {
            required: true,
            minlength: 8
          },
          action: "required"
        },
        messages: {
          pName: {
            required: "Please enter some data",
            minlength: "Your data must be at least 8 characters"
          },
          action: "Please provide some data"
        }
      });
    });
    
    
    
    
    
    

提交回复
热议问题