Comunidad de diseño web y desarrollo en internet online

usar validatorEmail y el del telefono en flex

Citar            
MensajeEscrito el 03 Ago 2010 07:58 pm
hola a todos! :D
bueno lo que pasa es que quiero utilizar el validatoremail y el del telefono pero no se como :oops: , he intentado con unos ejemplos que he visto y no he podido :roll: , haber si alguien me puede ayudar. He realizado todo en componentes (el .mxml ligado al .as) en una libreria y esta la he añadido a la aplicacion, donde creo un estado e inserto el componente. (estoy trabajando en adobe flex builder 3)

mi componente se llama altaInstructor en el e puesto los label, las cajas de texto y el boton salir y aceptar.

Código Flex :

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="234">
<mx:Script source="Ascript/altaInstructor.as"/>
   <mx:Label x="57" y="12" text="Nombre :" id="label2" fontWeight="bold"/>
   <mx:Label x="52" y="158" text="Empresa:" fontWeight="bold"/>
   <mx:Label x="52" y="98" text="Telefono :" fontWeight="bold"/>
   <mx:Label x="70" y="128" text="Email :" fontWeight="bold"/>
   <mx:TextInput restrict="0-9" x="121" y="96" id="txttelefono" maxChars="10"/>
   <mx:TextInput restrict="a-z @.W" x="121" y="126" id="txtemail"/>
   <mx:TextInput restrict="a-z " x="119" y="10" width="263" id="txtnombre"/>
   <mx:LinkButton x="314" y="200" label="Cancelar" click="cancelarSalir()"/>
   <mx:LinkButton x="240" y="200" label="Aceptar" click="checavacios()"/>
   <mx:TextInput restrict="a-z 0-9" x="121" y="156" width="237" id="txtempresa"/>
   <mx:Label x="10" y="68" text="Apellido Materno:" fontWeight="bold"/>
   <mx:Label x="10" y="38" text="Apellido Paterno:" fontWeight="bold"/>
   <mx:TextInput restrict="a-z " x="119" y="36" width="263" id="txtpaterno"/>
   <mx:TextInput restrict="a-z " x="119" y="66" width="263" id="txtmaterno"/>
   
</mx:Canvas>


luego tengo el actionScript siguiente

Código ActionScript :

// ActionScript file
import mx.controls.*;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;

var funcionCancel:Function;
var https:HTTPService = new HTTPService;
var https2:HTTPService = new HTTPService;
var https3:HTTPService = new HTTPService;

   
//boton Cancelar
   public function addeventoCancelarIn(cancel:Function):void
      {
      funcionCancel=cancel;
      }
   private function cancelarSalir():void
      {
      funcionCancel.call();
      limpiaalta();
      }
      
//alta de instructor   
   private function checavacios():void
      {
      if(txtnombre.text=="" || txtpaterno.text==""||txtmaterno.text==""||txtempresa.text=="" || txttelefono.text=="" || txtemail.text=="")
         {
         Alert.show('Existe(n) campo(s) en blanco');
         }
      else  //aqui esdonde creo debe de ir otro if para ver si esta bien el correo y el telefono

         {   
         checa();
         }
      }
   
//checa alta
   private function checa():void
      {
         var param:Object = new Object();
         param["nombre"]=txtnombre.text;
         param["paterno"]=txtpaterno.text;
         param["materno"]=txtmaterno.text;
               
      https.resultFormat = "e4x";
      https.url = "http://localhost/sacado/checaaltai.php";
      https.method = "POST";
      https.addEventListener(ResultEvent.RESULT,resul);
      https.send(param);
      
      }
   
   private function resul(evento:ResultEvent):void
      {
      https.removeEventListener(ResultEvent.RESULT,resul);
      
      if (evento.result.toString()=='no')
         {
         altaInstru();
         }
         
      else if(evento.result.toString()!= 'no')
         {
         Alert.show("El Instructor ya existe");   
         return;
         }
      }
   

      
//alta
   private function altaInstru():void
      {
      var param2:Object = new Object();
      param2["ram"]=iRandom;
      param2["nombre"]=txtnombre.text;
      param2["paterno"]=txtpaterno.text;
      param2["materno"]=txtmaterno.text;
      param2["telefono"]=txttelefono.text;
      param2["email"]=txtemail.text;
      param2["empresa"]=txtempresa.text;
      
      https2.resultFormat = "e4x";
      https2.url = "http://localhost/sacado/altai.php";
      https2.method = "POST";
      https2.send(param2);
      
      limpiaalta();
            
      }
      

//limpia alta de instructor
   private function limpiaalta():void
      {
      txtnombre.text="";
      txtpaterno.text="";
      txtmaterno.text="";
      txttelefono.text="";
      txtemail.text="";
      txtempresa.text="";
      }



Lo que quiero hacer es que al presionar el boton aceptar se mande llamar a checavacios() y que ya que verifique que no hay vacios tambiem verifique que este bien escrito el correo y el telefono (con validator...) si esta bien manda llamar a checa() y si no mande un mensaje para que el usuario corrija.

De antemano mil gracias a quien me pueda ayudar. :lol:

Por BERENOG

6 de clabLevel



Genero:Femenino  

chrome
Citar            
MensajeEscrito el 03 Ago 2010 08:52 pm
Tienes que declarar los validators, ya sea por código on en tags MXML (con el source y las reglas que le aplicas), luego haces un array de Validators y usas el método estático Validator.validateAll par correrlos a todos, te dará true si pasa o sino un array de errores (uno por cada validator que falle)
Acá hay un ejemplo bastante sencillo, pregunta lo que no entiendas: http://blog.flexexamples.com/2007/08/13/validating-flex-forms-using-the-validator-classes/

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 24 Ago 2010 10:22 pm
LISTO EL CODIGO QUEDO ASI:

....

Código Flex :

   private function init():void 
      {
        validatorArr = new Array();
        validatorArr.push(validaEmail);
        validatorArr.push(validaTel);
        validatorArr.push(validanom);
        validatorArr.push(validapa);
        validatorArr.push(validama);
        validatorArr.push(validaemp);
        }

   private function validateForm():void 
      {
        var validatorErrorArray:Array = Validator.validateAll(validatorArr);;
        var isValidForm:Boolean = validatorErrorArray.length == 0;
        if (isValidForm) 
           {
            altaInstru();
            } 
        else 
           {
            Alert.show("Datos no validos o en blanco..");
           }
      }
            
   private function resetForm():void 
      {
        txtnombre.text="";
      txtpaterno.text="";
      txtmaterno.text="";
      txttelefono.text="";
      txtemail.text="";
      txtempresa.text="";
        }

...

Y EL ESCRIP

Código ActionScript :

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="800" height="376" creationComplete="init(); init2()">
   <mx:Script source="Ascript/altaIns.as"/>
   <mx:Label x="36" y="63" text="Nombre:" fontWeight="normal"/>
   <mx:TextInput restrict="a-z " x="97" y="61" width="263" id="txtnombre"/>
   <mx:Label x="21" y="102" text="A. Paterno:" fontWeight="normal"/>
   <mx:TextInput restrict="a-z " x="97" y="100" width="263" id="txtpaterno"/>
   <mx:Label x="19" y="141" text="A. Materno:" fontWeight="normal"/>
   <mx:TextInput restrict="a-z " x="97" y="139" width="263" id="txtmaterno"/>
   <mx:Label x="30" y="183" text="Telefono:" fontWeight="normal"/>
   <mx:TextInput restrict="0-9" x="97" y="181" id="txttelefono" maxChars="10"/>
   <mx:Label x="44" y="221" text="E-mail:" fontWeight="normal"/>
   <mx:TextInput restrict="a-z @.W0-9_" x="97" y="220" id="txtemail"/>
   <mx:Label x="31" y="260" text="Empresa:" fontWeight="normal"/>
   <mx:TextInput restrict="a-z 0-9" x="97" y="260" width="237" id="txtempresa"/>
   <mx:LinkButton x="745" y="344" label="Salir" click="resetForm(); cancelarSalir()"/>
   <mx:Label x="10" y="10" text="Datos de Nuevo Instructor:" width="233" fontWeight="bold" fontSize="11"/>
   <mx:Label x="413" y="10" text="Instructores:" width="233" fontWeight="bold" fontSize="11"/>
   
   <mx:EmailValidator id="validaEmail" required="true" source="{txtemail}" property="text" missingAtSignError="Falta arroba (@) en su dirección e-mail"
         missingUsernameError="Falta nombre de usuario en su dirección e-mail"
         missingPeriodInDomainError="Falta un punto (.) para el dominio"
         tooManyAtSignsError="Su dirección contiene más de un arroba (@)"
         invalidCharError="Su dirección e-mail contiene caracteres inválidos"
         invalidPeriodsInDomainError="El dominio de su dirección e-mail tiene puntos (.) inválidos"
         invalidDomainError="El dominio de su dirección e-mail tiene formato inválido"
         invalidIPDomainError="El IP de su dominio es inválido"
         requiredFieldError="Este campo es requerido"/>
         
   <mx:PhoneNumberValidator id="validaTel" required="true" source="{txttelefono}" property="text" wrongLengthError="El telefono debe ser de 10 digitos" requiredFieldError="Este campo es requerido"/>
   <mx:StringValidator id="validanom" required="true" property="text" source="{txtnombre}" requiredFieldError="Este campo es requerido"/>
   <mx:StringValidator id="validama" required="true" property="text" source="{txtmaterno}" requiredFieldError="Este campo es requerido"/>
   <mx:StringValidator id="validapa" required="true" property="text" source="{txtpaterno}" requiredFieldError="Este campo es requerido"/>
   <mx:StringValidator id="validaemp" required="true" property="text" source="{txtempresa}" requiredFieldError="Este campo es requerido"/>
   <mx:DataGrid x="413" y="37" width="377" id="dg_instructor" height="272">
      <mx:columns>
         <mx:DataGridColumn textAlign="center" width="40" headerText="Folio" dataField="folioi" />
         <mx:DataGridColumn width="200" headerText="Nombre" dataField="nombrei" />
         <mx:DataGridColumn headerText="Empresa" dataField="empresai"/>
      </mx:columns>
   </mx:DataGrid>
   <mx:Button x="322" y="302" label="Alta" click="validateForm()"/>
   <mx:VRule x="380" y="5" width="14" height="319"/>
   
</mx:Canvas>


MUCHAS GRACIAS!! :lol: 

Por BERENOG

6 de clabLevel



Genero:Femenino  

chrome

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.