search
Homephp教程PHP开发A brief analysis of BootStrap Validator's problems with hidden domain verification and instant verification of program assignments

Question 1:

The following code:

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

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;
}
}
}
}
});

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);

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();

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


Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools