1

我使用的是bootstrapvalidator,它適用於以下情況。bootstrapvalidator通過自定義消息手動觸發

$('.login-form').bootstrapValidator({ 
    message: 'This value is not valid', 
    feedbackIcons: { 
     valid: 'glyphicon glyphicon-ok', 
     invalid: 'glyphicon glyphicon-remove', 
     validating: 'glyphicon glyphicon-refresh' 
    }, 
    fields: { 
     password: { 
      validators: { 
       notEmpty: { 
        message: 'The password is required and cannot be empty' 
       } 
      } 
     }, 
     email: { 
      validators: { 
       notEmpty: { 
        message: 'The email is required and cannot be empty' 
       }, 
       emailAddress: { 
        message: 'The input is not a valid email address' 
       } 
      } 
     } 
    } 
}); 

我提交一份行動提交一個Ajax請求,回答例如在JSON

errors: {user: 'Username does not exist', password: 'wrong password'}

我怎樣才能手動觸發對bootstrapvalidator表單輸入字段,這些服務器錯誤服務器?

+0

你有什麼確切的「手動觸發」錯誤是什麼意思? – webeno 2014-10-26 19:56:09

+0

我的意思是顯示輸入字段 – user391986 2014-10-26 19:57:04

+0

上的服務器錯誤,意思是在鍵入而不是在發佈後觸發?也許這只是我,但我不明白,對不起... – webeno 2014-10-26 20:03:08

回答

1

使用remote validator如下:

$('.login-form').bootstrapValidator({ 
    fields: { 
     username: { 
      message: 'The username is not valid', 
      validators: { 
       // The validator will create an Ajax request 
       // sending { username: 'its value' } to the back-end 
       remote: { 
        message: 'The username is not available', 
        url: '/path/to/backend/' 
       } 
      } 
     } 
    } 
});