我有我認爲是一個簡單的要求,但我不知道如何實現它。引導驗證器 - 可以有條件地調用遠程驗證器?
我有一個用戶登記表和用戶名字段有一堆驗證檢查:
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'
},
}
}
我的遠程驗證器檢查該用戶名沒有已被使用。問題是遠程驗證器與其他驗證器一起在每個按鍵上被調用。實際上只有在該字段的所有其他驗證都爲真時才調用遠程驗證器纔有意義。任何想法如何實現?
有關#1021 [在其他驗證後運行遠程驗證](https://github.com/nghuuphuoc/bootstrapvalidator/issues/1021) – kross 2014-11-24 22:31:00