Showing posts with label flex. Show all posts
Showing posts with label flex. Show all posts

Thursday, January 5, 2012

Flex Email address validation component

I was attempting to find a decent email validation component for flex - one with validators built in and all the bells and whistles.  I wasn't able to find one at a quick glance, so I put this guy together, and it seems to actually be working so far :O

<?xml version="1.0" encoding="utf-8"?>
<!--
 Created By:  Russ Hammett
 Create Date: 2012-01-03
 Description: Text input that validates an email address.
      use "required" to control if the email address
      is required.
      
      access the public variable isValidEmail to determine
      if validation passed on the email address
 Modified By: Russ Hammett
 Modify Date: 2012-01-06
 Modify Desc: Updated validateEmail function to be public and
      update errorString accordingly when validation fails or passes.
-->
<mx:TextInput xmlns:mx="http://www.adobe.com/2006/mxml"
  maxChars="50" 
  creationComplete="onCreationCompleted();"
  focusOut="validateEmail();" >
 
 <mx:Script>
  <![CDATA[
   import mx.events.ValidationResultEvent;
   
   private var _isValidEmail:Boolean = true;
   
   public function set isValidEmail(value:Boolean):void
   {
    _isValidEmail = value; 
   }
   [Bindable]
   public function get isValidEmail():Boolean
   {
    return _isValidEmail;
   } 
   
   [Bindable]
   public var required:Boolean = false;
   
   /**
    *  On Creation Completed
    * */
   private function onCreationCompleted():void
   {
    if (required)
    {
     emailValidator.enabled = true;
    }
    else
    {
     emailValidator.enabled = false; 
    }
    
   }
   
   /**
    *  Validate Email
    * */
   public function validateEmail():void
   {

    var vldEmail:ValidationResultEvent;
   
    if (this.length > 0)
    {
     emailValidator.enabled = true;
     vldEmail = emailValidator.validate(this.text);
     
     if (vldEmail.type == ValidationResultEvent.VALID)
     {
      isValidEmail = true;
      this.errorString = '';
     }
     else
     {
      isValidEmail = false;
      this.errorString = vldEmail.message;
     }
     
    }
    else
    {
     emailValidator.enabled = false;
     
     if (required)
     {
      emailValidator.enabled = true;
      vldEmail = emailValidator.validate(this.text);
      
      isValidEmail = false;
      this.errorString = vldEmail.message;
     }
     else
     {
      isValidEmail = true;
      this.errorString = '';
     }
    }
   }
   
  ]]>
 </mx:Script>
 
 <mx:EmailValidator 
  id="emailValidator" 
  source="{this}"
  property="text"
  required="{required}"
  requiredFieldError="Email Field is Required."
  invalidCharError="Invalid characters in your email address." 
  invalidDomainError= "The domain in your email address is incorrectly formatted." 
  invalidIPDomainError="The IP domain in your email address is incorrectly formatted." 
  invalidPeriodsInDomainError="The domain in your email address has consecutive periods." 
  missingAtSignError="Missing an at character in your email address." 
  missingPeriodInDomainError="The domain in your email address is missing a period." 
  missingUsernameError="The username in your email address is missing." 
  tooManyAtSignsError="Too many at characters in your email address." /> 

</mx:TextInput>


Thanks http://www.bloggersentral.com/2009/04/how-to-show-code-in-blog-post.html#free for teaching me how to paste code (and making it look pretty) in blogger..

Thursday, December 1, 2011

Flex "Global" RSLs

I am looking into deploying our custom libraries in flex in a "Global RSL Library" fashion.  I'm not sure how exactly to describe what we're trying to do but I'm going to give it a shot.

In every example I've found thus far, when using RSLs, the path specified at compilation is either:
1) Relative to the deployment path of the application (swf)
2) An absolute path.

Due to our development process and site layout, neither of these above methods of using an RSL is ideal.  What I am hoping to find a solution for, is specifying a relative path for an RSL in relation to the web root.

e.g. if I specify /libs/rsl.swf as my path, when launching my swf located at http://192.168.1.50/someDirectory/someOtherDirectory/project.swf the swf will access the RSL at location http://192.168.1.50/libs/rsl.swf

The problem we are trying to avoid in option 1 is that our swf files are located in varying directories all over our site, and to have duplicate copies of the libraries all over is redundant, and makes updates to our libraries more difficult as we have to make sure to deploy in every path where the RSL exists.

Option 2 (Absolute path) does not work especially well either in that our code is tested and QAd in varying environments (but only compiled once in our dev environment) - so specifying our absolute production RSL URL in addition failover URLs for every environment prior to production has a very high margin for error, and as far as I can tell, compile options are not something that can be reviewed in our QA process (to ensure that the developer [me] put in the correct production RSL path)

Is what am I attempting to accomplish understood?  I cannot be the first person that has wanted to be able to do something like this, have I simply overlooked the solution on the interweb?

- Kritner