Ext. NET added custom verification JS Functions

Source: Internet
Author: User

ExtJS verification is very convenient. When using FormPanel, we can easily verify it. For example, set required items, regular expressions, and field types. For example:

The above verification is written as follows:

            <Listeners>                <ClientValidation Handler="#{btnSave}.setDisabled(!valid);
#{tbSave}.setDisabled(!valid);#{btnSumbit1}.setDisabled(!valid);#{btnSumbit2}.
setDisabled(!valid);var valCs=valid ? valaccept : valexclamation;
var msg=valid ? 
<Span style = color: green;> data can be submitted after verification is passed </span>:
<Span style = color: red;> the input is incorrect. Check the marked red. </Span>;
this.getBottomToolbar().setStatus({text :msg, iconCls: valCs});
ShowMsg (Note: msg, valCs); "/> </Listeners>

However, we often need to write scripts for some complex verifications. So how can we achieve general purpose? For example:

The total number of S, M, L, and XL on the Left cannot exceed 2, and the number of S, M, L, and XL on the right cannot exceed 6. First, you can define the following verification JS to verify whether the number exceeds the maximum value.

Function valSumMax (ids, maxValue, msg ){
If (ids! = Null & ids. length> 0 ){
Var _ temp = 0;
For (var I = 0; I <ids. length; I ++ ){
Var value = Ext. getCmp (ids [I]). getValue ();
If (! IsNaN (value )){
_ Temp + = value;
If (_ temp> maxValue ){
Var message = {IsVal: false, Message: msg! = ""? Msg: ("exceeds the maximum value" + maxValue + ". ")};
Return message;
}
}
}
}
Var message = {IsVal: true, Message :};
Return message;
} To achieve general purpose, the following JS functions are defined:
Function CustomValidator (){
Var msg = valSumMax (ids1, 2, "Only two pieces of beauty consultant clothing can be entered. Modify the total number. ");
If (! Msg. IsVal)
Return msg;
Msg = valSumMax (ids2, 6, "you can enter a maximum of 6 beauticians. Modify the total number. ");
Return msg;
}
Function ValCustomValidator (isVal, valid ){
If (typeof (valid )! = Undefined &&(! Valid ))
Return valid;
If (typeof (isVal) = undefined | isVal = null | isVal ){
Var msg = CustomValidator ();
If (! Msg. IsVal ){
Ext. MessageBox. show ({
Title: error,
Msg: msg. Message,
Buttons: Ext. MessageBox. OK,
Icon: Ext. MessageBox. ERROR
});
Return false;
} Else {
Return true;
}
} Else {
Return CustomValidator ();
}
} Finally, write the listening verification Handler. This can be written as follows:

_ Fp. Listeners. ClientValidation. Handler =
@"
Var isCheckd = valid; var msgs; var msg =;
If (t

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.