我正在使用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表单输入字段上手动触发这些服务器错误?
如下使用远程验证器:
$('.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/'
}
}
}
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句