Flex4 form verification [focus on ComboBox verification]

Source: Internet
Author: User

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
  1. <Span Style="Font-size: Medium">Function vaidateform (): void {
  2. VaRALL: Array=Validator. Validateall ([numvd, emailvd, combovalidator]);
  3. If (All. Length= 0 ){
  4. Alert. Show ("verified ");
  5. // You can send a request to submit a form.
  6. }
  7. }</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
  1. <Span Style="Font-size: Medium"><FX: Style>
  2. @ Namespace s "Library: // ns.adobe.com/flex/spark ";
  3. @ Namespace MX "Library: // ns.adobe.com/flex/mx ";
  4. . Errortip
  5. {
  6. Fontsize: 16;
  7. }
  8. MX | alert {
  9. Fontsize: 16;
  10. }
  11. </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
  1. <Span style ="Font-size: Medium">PackageOreilly. cookbook
  2. {
  3. ImportMX. validators. validationresult;
  4. ImportMX. validators. validator;
  5. Public ClassCombovalidatorExtendsValidator
  6. {
  7. // If no project is selected in ComboBox, this error message is returned.
  8. PublicVaR error: string;
  9. // If the developer pushes a custom project into the ComboBox array (I have seen many of them in this case)
  10. // We will compare this item with the selected item.
  11. PublicVaR prompt: string;
  12. PublicFunction combovalidator (){
  13. Super();
  14. }
  15. // Here we perform two checks:
  16. // 1. Is there any project selected in ComboBox?
  17. // 2. Have the developer added a custom project to ComboBox?
  18. // If any of the conditions is true, an error is returned.
  19. OverrideProtectedFunction dovalidation (value: Object): Array
  20. {
  21. VaR results: array = [];
  22. If(Value as string = prompt | value =Null){
  23. VaR Res: validationresult =NewValidationresult (True,"","", Error );
  24. Results. Push (RES );
  25. }
  26. ReturnResults;
  27. }
  28. }
  29. } </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
  1. <Span Style="Font-size: Medium"><S: Application Xmlns: FX=Http://ns.adobe.com/mxml/2009"
  2. Xmlns: S="Library: // ns.adobe.com/flex/spark"
  3. Xmlns: MX="Library: // ns.adobe.com/flex/mx"
  4. Xmlns: cookbook="Oreilly. Cookbook .*"
  5. Creationcomplete="Init ()"
  6. ></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
  1. span style = " font-size: medium " FX: declarations
  2. cookbook: combovalidator prompt = "mycombox" id = "combovalidator" error = "select one" source = "{mycombox}" property = "selecteditem" />
  3. FX: declarations span >

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.