// Get plugin instance
var bootstrapValidator = $(form).data('bootstrapValidator');
// and then call method
bootstrapValidator.methodName(parameters)
$(form).bootstrapValidator(methodName, parameters);
// The first way
$(form)
.data('bootstrapValidator')
.updateStatus('birthday', 'NOT_VALIDATED')
.validateField('birthday');
// The second one
$(form)
.bootstrapValidator('updateStatus', 'birthday', 'NOT_VALIDATED')
.bootstrapValidator('validateField', 'birthday');
$('#defaultForm').bootstrapValidator({
fields: {
username: {
message: 'The username is not valid',
validators: {
notEmpty: {
message: 'The username is required and can\'t be empty'
}
}
}
},
submitHandler: function(validator, form, submitButton) {
// a)
// Use Ajax to submit form data
//$.post(form.attr('action'), form.serialize(), function(result) {
// ... process the result ...
//}, 'json');
//b)
// Do your task
// ...
// Submit the form
validator.defaultSubmit();
}
});
$('#loginForm').bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
submitHandler: function(validator, form, submitButton) {
$.post(form.attr('action'), form.serialize(), function(result) {
// The result is a JSON formatted by your back-end
// I assume the format is as following:
// {
// valid: true, // false if the account is not found
// username: 'Username', // null if the account is not found
// }
if (result.valid == true || result.valid == 'true') {
// You can reload the current location
window.location.reload();
// Or use Javascript to update your page, such as showing the account name
// $('#welcome').html('Hello ' + result.username);
} else {
// The account is not found
// Show the errors
$('#errors').html('The account is not found').removeClass('hide');
// Enable the submit buttons
$('#loginForm').bootstrapValidator('disableSubmitButtons', false);
}
}, 'json');
},
fields: {
username: {
validators: {
notEmpty: {
message: 'The username is required'
}
}
},
password: {
validators: {
notEmpty: {
message: 'The password is required'
}
}
}
}
});
// Enable the password/confirm password validators if the password is not empty
$('#signupForm').find('[name="password"]').on('keyup', function() {
var isEmpty = $(this).val() == '';
$('#signupForm').bootstrapValidator('enableFieldValidators', 'password', !isEmpty)
.bootstrapValidator('enableFieldValidators', 'confirm_password', !isEmpty);
if ($(this).val().length == 1) {
$('#signupForm').bootstrapValidator('validateField', 'password')
.bootstrapValidator('validateField', 'confirm_password');
}
});
$("#isAllValid").on("click", function(){
alert($("#defaultForm").data('bootstrapValidator').isValid());
});
$("#isAllValid").on("click", function(){
alert($("#defaultForm").data('bootstrapValidator').isValid());
if(!$("#defaultForm").data('bootstrapValidator').isValid()) {
$("#defaultForm").data('bootstrapValidator').resetForm();
}
});
$('#defaultForm').bootstrapValidator({
fields: {
username: {
message: 'The username is not valid',
validators: {
notEmpty: {
message: 'The username is required and can\'t be empty'
}
}
},
stringLength: {
min: 6,
max: 30,
message: 'The username must be more than 6 and less than 30 characters long'
}
}
});
$("#setname").on("click", function(){
$("input[name=username]").val('san');
var bootstrapValidator = $("#defaultForm").data('bootstrapValidator');
bootstrapValidator.updateStatus('username', 'NOT_VALIDATED').validateField('username');
//错误提示信息变了
});
$(form).bootstrapValidator(options).bootstrapValidator('validate');
// or
$(form).bootstrapValidator(options);
$(form).data('bootstrapValidator').validate();
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有