3 Replies Latest reply on Aug 30, 2011 8:42 AM by simon1tan

    Validation wrong focus?

    simon1tan

      Hi, I have a submit button that validates before submitting the data. When I enter data into the field and click on the submit button, it alerts with the message and refocuses on the field. If I press submit again, it checks fine. Why does it not check fine the first time? I added this.getField("Submit").setFocus() to the submit function to see if that'll fix the problem, no go. I read somewhere to use xfa.host.messageBox() but I'm not using xfa and don't really plan to. Any ideas?

      if(!CheckField("firstname","First name is mandatory")) {return;}
       
      function CheckField(name,message){
        var f = getField(name);
        if(f.value == ""){
          app.alert(message);
          f.setFocus();
          return false;
        }
        return true;
      }

        • 1. Re: Validation wrong focus?
          try67 MVP & Adobe Community Professional

          This code does not compile at all. You're calling return outside of a function (in the first line).

          How exactly are you using this code? Where is it located?

          • 2. Re: Validation wrong focus?
            try67 MVP & Adobe Community Professional

            I would use something like this instead as the Submit button's MouseUp event (of course, you can replace mailDoc with any other method for submitting the file):

             

            if(CheckField("firstname","First name is mandatory")) {mailDoc()}

             

            function CheckField(name,message){
              var f = getField(name);
              if(f.value == ""){
                app.alert(message);
                f.setFocus();
                return false;
              }
              return true;
            }

            • 3. Re: Validation wrong focus?
              simon1tan Level 1

              Sorry try67, I just didn't put the whole thing in. The submit button calls submit() and it returns if CheckField is fails. It's just the the first click will fail and the second click will succeed. It's as if the data in the field was not committed. Weird. That's why I tried to setFocus() on another field but still no go. Maybe I can do something with the blur event?

               

              function submit(){

                   if(!CheckField("firstname","First name is mandatory")) {return;}

                   if(!CheckField("lastname","Last name is mandatory")) {return;}

                   this.submitForm({cURL: "http://localhost/printvars.php",cSubmitAs: "HTML"});

              }

               

              function CheckField(name,message){

                   var f = getField(name);

                   if(f.value == ""){

                        app.alert(message);

                        f.setFocus();

                        return false;

                   }

                   return true;

              }