Home > php教程 > PHP开发 > body text

A brief analysis of BootStrap Validator's problems with hidden domain verification and instant verification of program assignments

高洛峰
Release: 2016-12-03 10:25:02
Original
1458 people have browsed it

Question 1:

The following code:

<input type="hidden" name="productId"/>
Copy after login
$("#addForm").bootstrapValidator({
fields: {
productId: {
validators: {
notEmpty: {
message: &#39;请选择一个商品&#39;
}
}
}
}
});
Copy after login

Such a configuration does not verify the form element productId when submitting. That is because the default configuration of bootstrapValidator is for "hidden domain (:hidden), disabled domain ( :disabled), that field (:not(visible))" are not verified.

Solution:

$("#addForm").bootstrapValidator({
//excluded:[":hidden",":disabled",":not(visible)"] ,//bootstrapValidator的默认配置
excluded:[":disabled"],//关键配置,表示只对于禁用域不进行验证,其他的表单元素都要验证
fields: {
productId: {
validators: {
notEmpty: {
message: &#39;请选择一个商品&#39;
}
}
}
}
});
Copy after login

Problem 2:

We often have such needs, as shown below:

A brief analysis of BootStrap Validators problems with hidden domain verification and instant verification of program assignments

After selecting the product, the product name will be displayed to the user in productName, and in Put a product ID in the hidden field productId.

Normally such operations are done by programs,

$("input[name=&#39;productId&#39;]").val(data.productId);
Copy after login

bootstrapValidator plug-in cannot capture such "program assignment events", so the verification effect cannot be achieved here, so we need to make a small Variation:

$("#addForm").bootstrapValidator({
//excluded:[":hidden",":disabled",":not(visible)"] ,//bootstrapValidator的默认配置
excluded:[":disabled"],//关键配置,表示只对于禁用域不进行验证,其他的表单元素都要验证
fields: {
productId: {
trigger:"change", //问题2.关键配置
validators: {
notEmpty: {
message: &#39;请选择一个商品&#39;
}
}
}
}
});
//赋值之后触发一次“change”事件
$("input[name=&#39;productId&#39;]").val(data.productId).change();
Copy after login

In this way, the bootrapValidator will capture the "change" event because it is triggered, achieving the verification effect

The above is the BootStrap Validator introduced by the editor for hidden domain verification and program assignment A brief analysis of the problem of instant verification, I hope it will be helpful to everyone


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!