我有一个我认为是简单的需求,但我不知道如何实现它。
我有一个用户注册表,用户名字段有一堆验证检查:
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'
},
}
}
我的远程验证器检查用户名是否尚未被使用。问题是远程验证器与其他验证器一起在每次按键时被调用。实际上,只有在此字段上的所有其他验证都为真时,调用远程验证器才有意义。有什么办法可以做到这一点吗?
发布于 2014-09-19 03:29:20
使用
模糊触发器:‘
’
点击此处查看更多信息:http://bootstrapvalidator.com/settings/#field-trigger
发布于 2016-01-17 16:42:01
我想你在这里寻找的是详细的。verbose: false,
将导致在“remote”发生之前进行所有其他验证。
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'
},
}
}
发布于 2016-03-29 10:04:41
如果可能的话,这样做是可行的。
remote: {
type: "POST",
url: 'RegistrationEmailCheck',
delay: 1000,
message: 'Your Message'
}
https://stackoverflow.com/questions/25764128
复制相似问题