仅在提交时启动表单验证

时间:2015-05-31 08:43:22

标签: jquery formvalidation-plugin

我的表单开始验证(with this plugin)用户开始输入的时间。例如,如果我有密码输入和重新输入密码输入,当在密码上键入第一个字符时,它会立即显示“密码不匹配”,但用户没有机会输入重新输入的密码。

如何在输入时禁用验证,仅在用户点击提交时显示错误?有什么选择吗?

但是,使用远程检查的用户名我确实希望它在输入时显示错误

$('#frm_user_details').formValidation('validate');

$('#frm_user_details').formValidation({
            framework: 'bootstrap',
            fields: {
                register_first_name: {
                    validators: {
                        notEmpty: {
                            message: 'Please enter your first name'
                        }
                    }
                },
                register_last_name: {
                    validators: {
                        notEmpty: {
                            message: 'Please enter your last name'
                        }
                    }
                },
                username: {
                    validators: {
                        notEmpty: {
                            message: 'Please enter a username.'
                        },
                        remote: {
                            type: 'POST',
                            url: '/core/services/validator.php',
                            message: 'That username is already taken.',
                            delay: 500
                        }
                    }
                },
                register_password: {
                    validators: {
                        notEmpty: {
                            message: 'The password is required and cannot be empty'
                        },
                        identical: {
                            field: 'register_password_retyped',
                            message: 'The password and its confirm must be the same'
                        }
                    }
                },
                register_password_retyped: {
                    validators: {
                        notEmpty: {
                            message: 'The confirm password is required and cannot be empty'
                        },
                        identical: {
                            field: 'register_password',
                            message: 'The password and its confirm must be the same'
                        }
                    }
                },

            },
            onError: function(e) {
                e.preventDefault();
                $('#create_account').removeClass('button-disabled');
            },
            onSuccess: function(e) {
                e.preventDefault();
                $('#create_account').addClass('button-disabled');
                    THIS.services.submitHandler();
                }
            }
        });

2 个答案:

答案 0 :(得分:1)

这里提到API docs describing Settings object结构: disabled属性应为$(formSelector).formValidation({ live : disabled, //other properties ,以防止对用户输入进行验证。 - 禁用实时验证。只有在提交表单后才会显示错误消息

delete

答案 1 :(得分:0)

为了完成@Shershen的答案,“禁用”应该与'禁用'一起使用。只是一个小细节。

$(document).ready(function() {
    $('<your_selector>').formValidation({
        live : 'disabled'
    });
});