【问题标题】:Bootstrap Validator - possible to conditionally call remote validator?引导验证器 - 可以有条件地调用远程验证器吗?
【发布时间】:2014-09-10 11:23:33
【问题描述】:

我有一个我认为很简单的要求,但我不知道如何实现它。

我有一个用户注册表单,并且用户名字段有一堆验证检查:

    fields: {
        username: {
            message: 'The username is not valid',
            validators: {
                notEmpty: {
                    message: 'The username is required and cannot be empty'
                },
                stringLength: {
                    min: 6,
                    max: 30,
                    message: 'The username must be between 6 and 30 characters long'
                },
                regexp: {
                    regexp: /^[a-zA-Z0-9]+$/,
                    message: 'The username can only consist of alphabetical and number'
                },
                different: {
                    field: 'password',
                    message: 'The username and password cannot be the same as each other'
                },
                remote: {
                    message: 'The username is not available',
                    url: '/api/username/valid',
                    type: 'GET'
                },
            }
        }

我的远程验证器检查该用户名是否尚未被使用。问题是远程验证器与其他验证器一起在每次按键时被调用。实际上,只有在该字段上的所有其他验证都为真时调用远程验证器才有意义。有什么想法可以实现吗?

【问题讨论】:

标签: jquery twitter-bootstrap validation


【解决方案1】:

使用

触发器:'模糊'

在此处查看更多信息:http://bootstrapvalidator.com/settings/#field-trigger

【讨论】:

    【解决方案2】:

    我认为您正在这里寻找详细verbose: false,将导致所有其他验证在“远程”发生之前发生。

    fields: {
        username: {
            verbose: false,
            message: 'The username is not valid',
            validators: {
                notEmpty: {
                    message: 'The username is required and cannot be empty'
                },
                stringLength: {
                    min: 6,
                    max: 30,
                    message: 'The username must be between 6 and 30 characters long'
                },
                regexp: {
                    regexp: /^[a-zA-Z0-9]+$/,
                    message: 'The username can only consist of alphabetical and number'
                },
                different: {
                    field: 'password',
                    message: 'The username and password cannot be the same as each other'
                },
                remote: {
                    message: 'The username is not available',
                    url: '/api/username/valid',
                    type: 'GET'
                },
            }
        }
    

    【讨论】:

      【解决方案3】:

      如果可能的话,这样做可以工作。

         remote: {
                              type: "POST",
                              url: 'RegistrationEmailCheck',
                              delay: 1000,
      
                              message: 'Your Message'
                           } 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-05-25
        • 1970-01-01
        • 1970-01-01
        • 2022-11-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多