2016-11-06 125 views
0

我使用快遞驗證器插件快遞快遞-校驗中斷校驗器鏈

var input = { 
      'username': { 
       notEmpty: true, 
       isEmail: { 
        errorMessage: 'Invalid Email.' 
       } 
      }, 
      'password': { 
       notEmpty: true, 
       errorMessage: 'Invalid Password' // Error message for the parameter 
      } 
     }; 

    req.checkBody(input); 
    var errors = req.validationErrors(); 
    if (errors) { 
     console.log(errors); 
    } 

如果我通過用戶名作爲空輸出

[ { param: 'username', msg: 'Invalid param', value: '' }, 
    { param: 'username', msg: 'Invalid Email.', value: '' }, 
    { param: 'password', msg: 'Invalid Password', value: '' } ] 

如何剎車鏈條如果驗證的人失敗。

+0

提高他們的GitHub庫 – hjpotter92

+0

@ hjpotter92我會刪除這個問題,功能要求,提高功能請求 –

+1

保持的問題在這裏。一旦請求得到迴應,你可以回答它。 – hjpotter92

回答

1

此修復終於降落在v3.0.0!

req.getValidationResult().then(result => { 
    var errors = result.useFirstErrorOnly().array(); // enjoy an array with no duplicated errors for any given parameter! 
}) 
1

看起來像你需要添加錯誤信息爲空PARAM:

用戶名:{ notEmpty:{ 的errorMessage: '用戶名不能是emtpy' }, ISEMAIL:{ 的errorMessage : '不合規電郵。' } } ...

+0

是的,這是正確的,但我的問題是不同的,這是該圖書館已知的問題 –