Use jquery in the previous article. in validate for client verification (intermediate>), I introduced jquery. the three verification methods of validate. In this article, we will continue to introduce jquery based on the previous one. some common verification methods of validate.
Today, we will introduce the problems that will occur after jquery. Validate is used. We will introduce the following:
1. When using the 2nd methods in the previous article, writing verification rules in JSON format affects normal class usage. How can this problem be solved?
2. in ASP. NET, all the buttons will submit the form, so authentication is triggered. How can this problem be solved?
3. What should I do if I want to display the verification prompt information in a uniform place?
4. During the development process, I am not sure whether the written rules are correct. How can I debug them?
5. I am using the Microsoft Ajax control and want to monitor whether the dropdownlist is selected. Why does it not work?
6. How to implement advanced applications in radiobox, checkbox, and ListBox? How to specify the quantity?
Let's take a look:In the previous article, 2nd verification rules are written in JSON format, which affects normal class usage. How can this problem be solved?(See Middle-4.aspx for details)
First, let's take a look at how to write verification rules using 2nd methods:
<Asp: textbox id = "txtpwd" textmode = "password" runat = "server" cssclass = "{required: True, minlength: 6, messages: {required: 'You don't enter the password. How can this problem be solved? ', Minlength:' The password is too short, at least 6 bits '}}"> </ASP: textbox>
As you can see, this write verification rule is simple, but what if I want to apply other styles for this control? So now it's time to solve this problem. Add a code in the header of the page:
Jquery. Metadata. settype ("ATTR", "Validate ");
Because this authentication rule method depends on jquery. metadata can work normally, so we need. post on metadata and analyze jquery. metadata code. By default, it is used to detect the class attribute of the control:
Defaults :{
Type: 'class ',
Name: 'metadata ',
CRES :/({.*})/,
Single: 'metadata'
}
Can we change this attribute? Certainly, you can add the code on the page to change its detection attributes.
Next, we also need to modify the code on the page to change all the original "cssclass" to the detection attribute "Validate ",
In this way, the attributes stored in the verification rules are modified.
2nd:In ASP. NET, all the buttons will submit the form, so verification is triggered. How can this problem be solved?? (See the btnnovalidate button in the Middle-4.aspx for details)
In actual development, there are always n buttons on a page, because ASP. net mechanism, all controls will send back the page, and the form is submitted, but the whole form is jquery. validate is monitored, so as long as there is a place on the page that does not comply with the verification rules, any operation on the send-back page will be blocked, but in fact we only need to trigger one or two verification buttons, other buttons are not needed, so we have to find a solution.
The Code is as follows:
<Asp: button id = "btnnovalidate" runat = "server" text = "I won't trigger verification." cssclass = "cancel"/>
How easy is it?
3rd:I hope that the prompt information for verification can be displayed in a uniform place. How can this problem be solved?? (See Middle-5.aspx for details)
In the development process, there will be some special requirements. For example, if a tab page is used on the page, and the submit button is one, you need to put the verification prompt information in one place, easy to view,
To achieve this effect, you only need to add the following when writing verification rules in JS:
Errorplacement: function (error, element ){
Error.html(error.html () + "<br/> ");
Error. appendto ("# errorcontainer ");
}
An error message is contained in a label object, and an element is an object element that fails to be verified. With errorplacement, you can easily place the verification prompt information in a single location.
4th:During the development process, I am not sure whether the written rules are correct or how to debug them.? (See Middle-5.aspx for details)
This is relatively simple. jquery. Validate is already taken into consideration by default. You only need to add an attribute when writing rules in JS:
Debug: True
This means that the system is currently debugging and the form will not be submitted.
5th:I am using the Microsoft Ajax control and want to monitor whether the dropdownlist is selected. Why does it not work?? (See the gender in Middle-5.aspx for details)
When you use the dropdownlist cascade function in the Microsoft Ajax control, for example, provincial/municipal linkage. If the province does not have a choice, the city and district are grayed out, disabled, and disabled, the Code is as follows:
<Asp: dropdownlist id = "dropdownlist1" runat = "server" cssclass = "required" Disabled = "true">
<Asp: listitem> </ASP: listitem>
<Asp: listitem value = "1"> male </ASP: listitem>
<Asp: listitem value = "0"> female </ASP: listitem>
</ASP: dropdownlist>
This dropdownlist is forcibly disabled on my side. If "required" is added to this control, there will be no response, because in jquery. the validate code is not verified by default. For details about the code, see jquery. validate. js414 lines:
Not (": Submit,: reset,: image, [disabled]")
So for ease of use, we can modify the code to remove [disabled] and change it:
Not (": Submit,: reset,: Image ")
In this way, refresh the page and the verification will take effect.
6th:How to implement advanced applications in radiobox, checkbox, and ListBox? How to specify the quantity? (For more information, see radio-checkbox-select-demo.html.)
In this case, I directly reference the official examples of radiobox, checkbox, and ListBox applications, because the official examples are already well written.
The above is the use of jquery. validate for client verification intermediate-Next, this article is jquery. the problems encountered in the use of validate are introduced (all of them are encountered in the actual project and a summary is made, which will inevitably lead to omissions. If there is jquery. if you are experienced in validate development, you can download the source code to view details.
PS: The intermediate article is finished. The application of the advanced article is as follows. The advanced article mainly describes how to extend the verification method, group verification, and Ajax verification. Please wait!
Source code download: Click here to download