1 Reply Latest reply on Dec 11, 2007 2:26 AM by atta707

    Validator Issue

    Peter Hahmann Level 1
      Hi,

      My validator starts validating the form when it appears, not when i click the button. Please help me to find the error.

      Thanks,
      Peter


      Code:
      <mx:Script>
      <![CDATA[

      import mx.events.ValidationResultEvent;
      import mx.validators.Validator;

      private function validateForm(event:MouseEvent):void {
      if (!loginOK && !cpfOK) {
      cfcErro.listarGeralErro(26, parentApplication.numIdioma);
      } else if (!loginOK) {
      cfcErro.listarGeralErro(25, parentApplication.numIdioma);
      } else if (!cpfOK) {
      cfcErro.listarGeralErro(43, parentApplication.numIdioma);
      } else {
      var arrValidatorError:Array = Validator.validateAll(arrValidacao);;
      var isValidForm:Boolean = arrValidatorError.length == 0;
      /* if (txtEmail.text == '' && arrValidatorError.length == 1) {
      isValidForm = true;
      } */
      if (isValidForm) {
      viewForm.selectedIndex++;
      } else {
      var err:ValidationResultEvent;
      var arrErrorMessage:Array = [];
      for each (err in arrValidatorError) {
      var errField:String = FormItem(err.currentTarget.source.parent).label
      arrErrorMessage.push(errField + " " + err.message);
      }
      Alert.show(arrErrorMessage.join("\n\n"), parentApplication.objLabels.label44, Alert.OK);
      }
      }
      }

      ]]>
      </mx:Script>


      //VALIDATOR ARRAY

      <mx:Array id="arrValidacao">

      <mx:StringValidator id="validaNome" source="{txtNome}" minLength="10" required="true" property="text"
      requiredFieldError="{parentApplication.objLabels.label45}"
      tooShortError="{parentApplication.objLabels.label46}" />

      <mx:StringValidator id="validaLogin" source="{txtLogin}" minLength="3" required="true" property="text"
      requiredFieldError="{parentApplication.objLabels.label45}"
      tooShortError="{parentApplication.objLabels.label46}" />

      <mx:StringValidator id="validaCPF" source="{txtCPF}" minLength="11" required="true" property="text"
      requiredFieldError="{parentApplication.objLabels.label45}"
      tooShortError="{parentApplication.objLabels.label46}" />

      <mx:StringValidator id="validaRG" source="{txtRG}" minLength="3" required="true" property="text"
      requiredFieldError="{parentApplication.objLabels.label45}"
      tooShortError="{parentApplication.objLabels.label46}" />

      <mx:StringValidator id="validaNascimento" source="{txtNascimento}" minLength="8" property="text"
      requiredFieldError="{parentApplication.objLabels.label45}"
      tooShortError="{parentApplication.objLabels.label46}" />

      <!-- <mx:StringValidator id="validaSexo" source="{radiogroupSexo}" minLength="3" required="true" property="selectedValue"
      requiredFieldError="{parentApplication.objLabels.label45}"
      tooShortError="{parentApplication.objLabels.label46}"
      trigger="{btnAvancar2}" triggerEvent="click"/>-->

      <mx:NumberValidator id="validaProfissao" source="{comboProfissao}" required="true" property="selectedIndex"
      lowerThanMinError="{parentApplication.objLabels.label45}" minValue="1" />

      <mx:NumberValidator id="validaEscolaridade" source="{comboEscolaridade}" required="true" property="selectedIndex"
      lowerThanMinError="{parentApplication.objLabels.label45}" minValue="1" />

      <mx:NumberValidator id="validaCargo" source="{comboCargo}" required="true" property="selectedIndex"
      lowerThanMinError="{parentApplication.objLabels.label45}" minValue="1" />

      <mx:EmailValidator id="validaEmail" source="{txtEmail}" property="text" required="false"
      requiredFieldError="{parentApplication.objLabels.label45}"
      invalidCharError="{parentApplication.objLabels.label112}"
      invalidDomainError= "{parentApplication.objLabels.label112}"
      invalidIPDomainError="{parentApplication.objLabels.label112}"
      invalidPeriodsInDomainError="{parentApplication.objLabels.label112}"
      missingAtSignError="{parentApplication.objLabels.label112}"
      missingPeriodInDomainError="{parentApplication.objLabels.label112}"
      missingUsernameError="{parentApplication.objLabels.label112}"
      tooManyAtSignsError="{parentApplication.objLabels.label112}" />

      </mx:Array>


      //FORM

      <mx:VBox id="boxTela2" width="100%" height="100%">

      <mx:Form id="formCNPJ" width="100%" height="100%">

      <mx:FormItem width="100%" label="{parentApplication.objLabels.label118}:">
      <mx:TextInput id="txtNome" text="{gridListagemERP.selectedItem.NOME}" width="100%"/>
      </mx:FormItem>

      <mx:FormItem label="{parentApplication.objLabels.label123}:">
      <mx:TextInput id="txtLogin" maxChars="10" width="100"/>
      </mx:FormItem>

      <mx:FormItem label="{parentApplication.objLabels.label119}:">
      <util:MaskedInput id="txtCPF" inputMask="###.###.###-##" width="130"/>
      </mx:FormItem>

      <mx:FormItem label="{parentApplication.objLabels.label121}:">
      <util:MaskedInput id="txtRG" inputMask="##.###.###-#" width="130" change="teste()"/>
      </mx:FormItem>

      <mx:FormItem label="{parentApplication.objLabels.label124}:">
      <mx:TextInput id="txtNascimento" width="130"/>
      <!--<util:MaskedInput id="txtNascimento" inputMask="##/##/####" width="130"/>-->
      </mx:FormItem>

      <mx:FormItem label="{parentApplication.objLabels.label125}:" direction="horizontal">
      <mx:RadioButtonGroup id="radiogroupSexo"/>
      <mx:RadioButton label="M" groupName="radiogroupSexo" selected="true"/>
      <mx:RadioButton label="F" groupName="radiogroupSexo"/>
      </mx:FormItem>

      <mx:FormItem label="{parentApplication.objLabels.label40}:">
      <mx:ComboBox id="comboProfissao" dataProvider="{arrProfissao}" labelField="PROFISSAO"/>
      </mx:FormItem>

      <mx:FormItem label="{parentApplication.objLabels.label128}:">
      <mx:ComboBox id="comboEscolaridade" dataProvider="{arrEscolaridade}" labelField="ESCOLARIDADE"/>
      </mx:FormItem>

      <mx:FormItem label="{parentApplication.objLabels.label71}:">
      <mx:ComboBox id="comboCargo" dataProvider="{arrCargo}" labelField="CARGO"/>
      </mx:FormItem>

      <mx:FormItem label="{parentApplication.objLabels.label122}:">
      <mx:TextInput id="txtNacionalidade"/>
      </mx:FormItem>

      <mx:FormItem width="100%" label="{parentApplication.objLabels.label85}:" direction="horizontal">
      <mx:TextInput width="250" id="txtEmail"/>
      <mx:CheckBox id="chkEmailMkt" label="{parentApplication.objLabels.label84}" selected="true" labelPlacement="right"/>
      </mx:FormItem>

      </mx:Form>

      <mx:HBox width="100%">
      <mx:Button id="btnVoltar2" label="{parentApplication.objLabels.label105}" click="viewForm.selectedIndex = 0"/>
      <mx:Spacer width="100%"/>
      <mx:Button id="btnAvancar2" label="{parentApplication.objLabels.label106}" click="validateForm(event)"/>
      </mx:HBox>

      </mx:VBox>