Bootstrap表单验证器不会重置

时间:2017-07-21 19:45:59

标签: javascript bootstrapvalidator

我正在使用联系表单,我使用的是Bootstrap Validator,但是我无法重置表单,Form运行良好,唯一的麻烦就是它赢了“#发送后重置。这是我的JS:

$(document).ready(function() {
$('#contact_form').bootstrapValidator({

    submitHandler: function(validator, form, submitButton) {
    $('#success_message').slideDown({ opacity: "show" }, "slow") // Do something ...
            $('#contact_form').data('bootstrapValidator').resetForm();

        var bv = form.data('bootstrapValidator');
        // Use Ajax to submit form data
        $.post(form.attr('action'), form.serialize(), function(result) {
            console.log(result);
        }, 'json');
    },

    fields: {
        name: {
            validators: {
                    stringLength: {
                    min: 4,
                    message: '*Este campo debe tener al menos 4 caracteres'
                },
                    notEmpty: {
                    message: '*Este campo es obligatorio'
                }
            }
        },
        mail: {
            validators: {
                notEmpty: {
                    message: '*Este campo es obligatorio'
                },
                emailAddress: {
                    message: '*Tu dirección de correo no es válida'
                }
            }
        },
        phone: {
            validators: {
                notEmpty: {
                    message: '*Este campo es obligatorio'
                },
                phone: {
                    country: 'MX',
                    message: '*Incluye un número de teléfono válido de 10 dígitos'
                }
            }
        },
        comment: {
            validators: {
                  stringLength: {
                    max: 200,
                    message:'Tu comentario no debe exceder de 200 caracteres'
                },
            }
        },
    }
})
});

我也尝试过使用它:

   $('#contact_form').bootstrapValidator('resetForm', true);    

但是之后我的表单会在发送之前重置,我收到的电子邮件是空白的...有关如何在发送后重置表单的任何想法吗?

0 个答案:

没有答案
相关问题