我有一个我认为很简单的需求,但我不知道如何实现它。
我有一个用户注册表,用户名字段有一堆验证检查:
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'
},
}
}
我的远程验证器检查用户名是否尚未被使用。问题是,每次按键时都会调用远程验证器和其他验证器。实际上,只有当该字段上的所有其他验证都为true时,才有意义调用远程验证器。有什么想法可以实现吗?
使用
触发器:"模糊"
点击此处查看更多信息:http://bootstrapvalidator.com/settings/#field-触发
我想您正在此处查找详细。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'
},
}
}
如果可能的话,这样做是可行的。
remote: {
type: "POST",
url: 'RegistrationEmailCheck',
delay: 1000,
message: 'Your Message'
}