bootstrapValidator验证表单后清除当次验证的方法

 用bootstrapValidator的resetForm()方法:



 

    $('#server-create-server-modal-form')
    .bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
        	serverCreateServerModalName: {
                message: '名称无效',
                validators: {
                    notEmpty: {
                        message: '名称不能为空'
                    },
                    stringLength: {
                        min: 1,
                        max: 30,
                        message: '名称只能为1至30个字符'
                    },
	                regexp: {
	                  	regexp: /^[a-zA-Z0-9_\.]+$/,
	                  	message: '名称只能为数字字母下划线'
              		}
                }
            },
            serverCreateServerModalType: {
                message: '类型无效',
                validators: {
                    notEmpty: {
                        message: '类型不能为空'
                    }
                }
            },
            serverCreateServerModalIp: {
                message: 'IP码无效',
                validators: {
                    notEmpty: {
                        message: 'IP不能为空'
                    },
                    regexp: {
                        regexp: /^(\d|\d\d|1\d\d|2[0-4]\d|25[0-5])(?:\.(\d|\d\d|1\d\d|2[0-4]\d|25[0-5])){3}$/g,
                        message: '请输入正确的IP'
                    }
                }
            }
        }
    })
    .on('success.form.bv', function(e) {
    	e.preventDefault();//取消submit默认提交效果
    	$("#server-create-server-modal-form")[0].reset();//重置表单,此处用jquery获取Dom节点时一定要加[0]
    	$("#server-create-server-modal-form").data('bootstrapValidator').resetForm();//清除当前验证的关键之处
    	$("#server-create-server-modal").modal("hide");
		toastr.success("创建服务器成功", "成功提示");
		$serverTable.bootstrapTable("refresh");
    });

 

你可能感兴趣的:(javascript,jquery,前端插件)