如何使用 bootstrapValidator 验证两封电子邮件(相同)
How to validate both email using bootstrapValidator (identical)
我正在使用 bootstrapValidator(相同)来检查两封电子邮件是否相同,它工作正常,但我希望在同一行中显示错误消息,现在它们在两行中。请参阅此处 https://screenshots.firefox.com/abfJ97LEjpAncVoW/localhost。我尝试了很多方法并在 google 中找到但没有得到任何解决方案。以下是我的验证码:
$('#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'
}
}
},
},
})
下面的代码解决了我的问题,我已经把它添加到这个下面 $('#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();
});
我正在使用 bootstrapValidator(相同)来检查两封电子邮件是否相同,它工作正常,但我希望在同一行中显示错误消息,现在它们在两行中。请参阅此处 https://screenshots.firefox.com/abfJ97LEjpAncVoW/localhost。我尝试了很多方法并在 google 中找到但没有得到任何解决方案。以下是我的验证码:
$('#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'
}
}
},
},
})
下面的代码解决了我的问题,我已经把它添加到这个下面 $('#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();
});