4 Replies Latest reply on Oct 7, 2014 1:30 PM by MatLac

    Validating a value based on a functions

    MatLac Level 1

      I created a function that basically is a an array that associates a numerical value to a string

       

      function myValidation(mip)

      {

      var text = "";

      var mipCodes = {
      "A100" : "String 1",
      "A101" : "String 2",
      "A102" : "String 3",
      "A103" : "String 4",
      "A104" : "String 5"

      }

       

      //When a MIP code is entered
      if (mip != "") text = mipCodes[mip];

      return text;
      }

       

      I want to use this function as a validation script, like if the function return an empty string (meaning the value was not found in the array), the value is not commited.

       

      I tried this validation script:

      if (text == "") event.rc = false;

       

      When this will work, I'll need to add other validation functions in a row before a value is commited.

        • 1. Re: Validating a value based on a functions
          try67 MVP & Adobe Community Professional

          You're never calling the myValidation function...

          • 2. Re: Validating a value based on a functions
            MatLac Level 1

            I didn't write it to shorten the post but the function is called and the correct value is returned.  By trial and errors, I was able to troubleshoot the problem but I don't understand my own solution.  Let me explain:

             

            In the function, I initiate 'text' as an empty string "".  Then, the function searches for a key and returns the value associated with that key by assigning the string to the variable 'text'.  So either it returns a string, or it returns the initially empty string.

             

            Back to the validation script
            if (text == "") event.rc = false;  //this doesn't evaluate as TRUE

            if (text == " ") event.rc = false;  //Strangely this does evaluate as TRUE

             

            This doesn't make sense as I never assigned a "SPACED" value to 'text'.  I will try to change the initial value of 'text' to let's say, "acrobat" and see what happens.

            • 3. Re: Validating a value based on a functions
              try67 MVP & Adobe Community Professional

              I can't help you without seeing the full code.

              • 4. Re: Validating a value based on a functions
                MatLac Level 1

                function Mip(mip)
                {

                //script d'association des codes MIP aux évènements
                //Version 2014-09-23

                var text = "";

                var mipCodes = {
                "A100" : "Minis. prov. ou féd.",
                "A101" : "Assist. (minis. ress. natur. / faune-enviro.)",
                "A102" : "Assist. (minis. ress. natur. / faune-faune)",
                "A103" : "Assist. (minis. revenu)"

                }

                //When a MIP code is entered
                if (mip != "") text = mipCodes[mip];

                return text;
                }

                 

                the validation script is:

                 

                if (event.value != ""){

                if (Mip(event.value) == " "){     //This part does not make sense but the entire script works, removing a value not included in the array

                  app.alert("Le code MIP entré n'est pas reconnu/supporté par l'application.", 0, 0, "CODE MIP INVALIDE");

                  event.rc = false;

                }

                else{

                var aMIP = [this.getField("OPE003.EVEN.1.MIP"), this.getField("OPE003.EVEN.2.MIP"), this.getField("OPE003.EVEN.3.MIP"), this.getField("OPE003.EVEN.4.MIP")];

                Duc(event, aMIP);

                }

                }