2017-10-15 56 views
0

我使用bootstrapValidator(相同)來檢查兩個電子郵件是否相同,其工作正常,但我想在同一行中的錯誤消息,現在他們在兩行。見這裏https://screenshots.firefox.com/abfJ97LEjpAncVoW/localhost。我嘗試了很多方法,發現在谷歌,但沒有得到任何解決方案。以下是我的驗證代碼:如何使用bootstrapValidator驗證兩個電子郵件(相同)

$('#formid').bootstrapValidator({ 

     feedbackIcons: { 
      valid: 'glyphicon glyphicon-ok', 
      invalid: 'glyphicon glyphicon-alert', 
      validating: 'glyphicon glyphicon-refresh' 
     }, 
     fields: { 
      firstmail: { 
       validators: { 
        notEmpty: { 
         message: 'The email address is required and can\'t be empty' 
        }, 
        emailAddress: { 
         message: 'The input is not a valid email address' 
        }, 
        identical: { 
         field: '2ndmail', 
         message: 'The email and its confirm are not the same' 
        } 
       } 
      }, 
      2ndmail: { 
       validators: { 
        notEmpty: { 
         message: 'The email address is required and can\'t be empty' 
        }, 
        emailAddress: { 
         message: 'The input is not a valid email address' 
        }, 
        identical: { 
         field: 'firstmail', 
         message: 'The email and its confirm are not the same' 
        } 
       } 
      }, 
      }, 

    }) 

回答

0

下面的代碼解決我的問題,我有這樣的$( '#formId')下方添加它bootstrapValidator({......});

$('#formid').bootstrapValidator({ 

feedbackIcons: { 
    valid: 'glyphicon glyphicon-ok', 
    invalid: 'glyphicon glyphicon-alert', 
    validating: 'glyphicon glyphicon-refresh' 
}, 
fields: { 
    firstmail: { 
     validators: { 
      notEmpty: { 
       message: 'The email address is required and can\'t be empty' 
      }, 
      emailAddress: { 
       message: 'The input is not a valid email address' 
      }, 
      identical: { 
       field: '2ndmail', 
       message: 'The email and its confirm are not the same' 
      } 
     } 
    }, 
    2ndmail: { 
     validators: { 
      notEmpty: { 
       message: 'The email address is required and can\'t be empty' 
      }, 
      emailAddress: { 
       message: 'The input is not a valid email address' 
      }, 
      identical: { 
       field: 'firstmail', 
       message: 'The email and its confirm are not the same' 
      } 
     } 
    }, 
    }, 

}) 

.on('error.validator.bv', function(e, data) { 
// $(e.target) --> The field element 
// data.bv  --> The BootstrapValidator instance 
// data.field  --> The field name 
// data.element --> The field element 
// data.validator --> The current validator name 

data.element 
    .data('bv.messages') 
    // Hide all the messages 
    .find('.help-block[data-bv-for="' + data.field + '"]').hide() 
    // Show only message associated with current validator 
    .filter('[data-bv-validator="' + data.validator + '"]').show(); 
});