BootStrap Validator on the problems of hidden domain verification and immediate validation of program assignment _javascript skills

Source: Internet
Author: User

Question 1:

The following code:

<input type= "hidden" name= "ProductId"/>
$ ("#addForm"). Bootstrapvalidator ({
fields: {
productId: {
validators: {
notempty: {message
: ' Please select a commodity '}}}}
;

Such a configuration does not validate the table cell ProductID at the time of submission because the bootstrapvalidator default configuration is for "hidden fields (: hidden), disabled domain (:D isabled), which field (: Not ( Visible)) "is not validated.

Workaround:

$ ("#addForm"). Bootstrapvalidator ({
//excluded:[": Hidden", ":d isabled", ": Not (visible)"],// Bootstrapvalidator's default configuration
excluded:[":d isabled"],//critical configuration, which means that only disabling domains are not validated, and other form elements are validated by
fields: {
ProductId: {
validators: {
notempty: {
message: ' Please select a commodity '
}
}}}
;

Question 2:

We tend to have such a demand as the following figure:

After the selection of goods will be in the ProductName to display the name of the product to the user, and in ProductID this hidden domain put a product ID.

In general, such operations are done by the program,

$ ("Input[name= ' productId ']"). Val (Data.productid);

Bootstrapvalidator This plugin cannot capture such "program assignment events", so there is no validation effect here, so we need to make a little workaround:

$ ("#addForm"). Bootstrapvalidator ({
//excluded:[": Hidden", ":d isabled", ": Not (visible)"],// Bootstrapvalidator's default configuration
excluded:[":d isabled"],//critical configuration, which means that only disabling domains are not validated, and other form elements are validated
fields: {
productId : {
trigger: "Change",//Issue 2. Key Configuration
validators: {
notempty: {
message: ' Please select an item '
}}
}
});
The "Change" event
("Input[name= ' productId ']") is triggered once after the assignment. Val (data.productid). Change ();

After that, the bootrapvalidator will be caught with the "change" event triggering the effect of the validation.

The above is a small set to introduce the bootstrap validator for hidden domain validation and procedures for real-time validation of the problem analysis, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.