1

我正在使用bootstrapvalidator,它适用于以下内容。

$('.login-form').bootstrapValidator({
    message: 'This value is not valid',
    feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
    },
    fields: {
        password: {
            validators: {
                notEmpty: {
                    message: 'The password is required and cannot be empty'
                }
            }
        },
        email: {
            validators: {
                notEmpty: {
                    message: 'The email is required and cannot be empty'
                },
                emailAddress: {
                    message: 'The input is not a valid email address'
                }
            }
        }
    }
});

我的提交操作向服务器提交了一个 ajax 请求,例如在 json 中回答

errors: {user: 'Username does not exist', password: 'wrong password'}

如何在 bootstrapvalidator 表单输入字段上手动触发这些服务器错误?

4

1 回答 1

1

使用远程验证器如下:

$('.login-form').bootstrapValidator({
    fields: {
        username: {
            message: 'The username is not valid',
            validators: {
                // The validator will create an Ajax request
                // sending { username: 'its value' } to the back-end
                remote: {
                    message: 'The username is not available',
                    url: '/path/to/backend/'
                }
            }
        }
    }
});
于 2014-10-26T21:12:30.827 回答