The last time we talked about simple form verification, we can configure the error message and click the button to perform all form verification. If the verification passes, how can we execute the submit task? This is generally the case. The following is the processing method for button click events.
XML Code
-
- <Span Style="Font-size: Medium">Function vaidateform (): void {
-
- VaRALL: Array=Validator. Validateall ([numvd, emailvd, combovalidator]);
-
- If (All. Length= 0 ){
- Alert. Show ("verified ");
-
- // You can send a request to submit a form.
-
- }
-
- }</Span>
Function vaidateform (): void {var all: array = validator. validateall ([numvd, emailvd, combovalidator]); If (all. length = 0) {alert. show ("verified"); // you can send a request to submit a form }}
For error message prompts, some people say that the font is too small to be nice, so the style is not properly configured for this problem, just as the font of the prompt box is too small, you can set the style.
Appendix
The configuration is as follows:
XML Code
-
- <Span Style="Font-size: Medium"><FX: Style>
-
- @ Namespace s "Library: // ns.adobe.com/flex/spark ";
-
- @ Namespace MX "Library: // ns.adobe.com/flex/mx ";
-
- . Errortip
- {
-
- Fontsize: 16;
-
- }
-
- MX | alert {
-
- Fontsize: 16;
-
- }
-
- </FX: Style></Span>
<FX: style> @ namespace s "Library: // ns.adobe.com/flex/spark"; @ namespace MX "Library: // ns.adobe.com/flex/mx ";. errortip {fontsize: 16;} MX | alert {fontsize: 16;} </FX: style>
Next let's talk about the ComboBox verification. This is not found in the common verification and must be manually written.
Combovalidator.
Java code
-
- <Span style ="Font-size: Medium">PackageOreilly. cookbook
-
- {
- ImportMX. validators. validationresult;
-
- ImportMX. validators. validator;
-
- Public ClassCombovalidatorExtendsValidator
-
- {
-
- // If no project is selected in ComboBox, this error message is returned.
-
- PublicVaR error: string;
- // If the developer pushes a custom project into the ComboBox array (I have seen many of them in this case)
-
- // We will compare this item with the selected item.
-
- PublicVaR prompt: string;
-
- PublicFunction combovalidator (){
-
- Super();
-
- }
- // Here we perform two checks:
-
- // 1. Is there any project selected in ComboBox?
-
- // 2. Have the developer added a custom project to ComboBox?
-
- // If any of the conditions is true, an error is returned.
-
- OverrideProtectedFunction dovalidation (value: Object): Array
-
- {
- VaR results: array = [];
-
- If(Value as string = prompt | value =Null){
-
- VaR Res: validationresult =NewValidationresult (True,"","", Error );
- Results. Push (RES );
-
- }
-
- ReturnResults;
-
- }
-
- }
-
- } </Span>
Package oreilly. cookbook {import MX. validators. validationresult; import MX. validators. validator; public class combovalidator extends validator {// if no project in ComboBox is selected, this error message public var error: string is returned; // If the developer pushes a custom project into the ComboBox array (I have seen many of them in this case) // We will compare this item with the selected item. Public var prompt: string; Public Function combovalidator () {super () ;}// here we perform two checks: // 1. is there any project selected in ComboBox? // 2. if the developer adds a custom project to ComboBox // if any of the conditions is true, an error override protected function dovalidation (value: Object): Array {var results: array = []; If (value as string = prompt | value = NULL) {var Res: validationresult = new validationresult (true, "", "", error ); results. push (RES) ;}return results ;}}}
Use the specific code.
XML Code
-
- <Span Style="Font-size: Medium"><S: Application Xmlns: FX=Http://ns.adobe.com/mxml/2009"
-
- Xmlns: S="Library: // ns.adobe.com/flex/spark"
- Xmlns: MX="Library: // ns.adobe.com/flex/mx"
-
- Xmlns: cookbook="Oreilly. Cookbook .*"
-
- Creationcomplete="Init ()"
- ></Span>
<S: Application xmlns: FX = "http://ns.adobe.com/mxml/2009" xmlns: S = "Library: // ns.adobe.com/flex/spark" xmlns: MX = "Library: // ns.adobe.com/flex/mx" xmlns: cookbook = "oreilly. cookbook. * "creationcomplete =" Init () ">
If no cookbook exists, it is matched with orelilly. cookbook is the package name of the AS file.
XML Code
- span style = " font-size: medium " FX: declarations
- cookbook: combovalidator prompt = "mycombox" id = "combovalidator" error = "select one" source = "{mycombox}" property = "selecteditem" />
- FX: declarations span >