Jquery Validate custom error message location

后端 未结 7 1828
一个人的身影
一个人的身影 2021-01-30 16:35

This looks very simply, but I can\'t figure it out. I\'m using the jquery validate plugin. I\'m trying to validate and

7条回答
  •  灰色年华
    2021-01-30 17:12

    HTML

    ... .... ' ...

    Javascript

    $(function () {
        $("#GoogleMapsApiKeyForm").validate({
          rules: {
              GoogleMapsAPIKey: {
                  required: true
              }
            },
            messages: {
                GoogleMapsAPIKey: 'Google maps api key is required',
            },
            errorPlacement: function (error, element) {
                if (element.attr("name") == "GoogleMapsAPIKey")
                    $("#GoogleMapsAPIKey-errorMsg").html(error);
            },
            submitHandler: function (form) {
               // form.submit(); //if you need Ajax submit follow for rest of code below
            }
        });
    
        //If you want to use ajax
        $("#GoogleMapsApiKeyForm").submit(function (e) {
            e.preventDefault();
            if (!$("#GoogleMapsApiKeyForm").valid())
                return;
    
           //Put your ajax call here
        });
    });
    

提交回复
热议问题