2 Replies Latest reply on Feb 2, 2010 8:01 AM by ndjustin20

    Dynamically make object/field required if another field is !=NULL

    ndjustin20 Level 1

        I am uploading the form I am working with and a screen shot of what I am trying to do.  I've figured out that "<validate nullTest="error"/>" is added to an object when i change it to "user required" within the properties on the side of the livecycle wysiwyg environment.  I really like how adobe handles the required error and stops all other processes while also outlining the menacing field in red.

       

      What I need to do is store the null test but I'm not sure how I can drop this information into the xml.  I tried using document.write but that didn't work so I'm not sure what I am doing wrong.

       

      <script contentType="application/x-javascript">

      if (RadioLocation.rawValue == "1")

      {

      var required = "<validate nullTest="error"/>";

      document.write(required);


      }//end if

      </script>

       

       

      I need something like this I think but am not too sure how to get this to work exactly.  I though I could put this inside the object I wanted to become required dynamically if RadioLocation.rawValue == "1" but it didn't work so I'm not sure what I am doing wrong.  I'm pretty certain it has something to do with the syntax but have no idea what i could do differently in this case as I am brand new to livecycle code.

       

       

       

      Justin

        • 1. Re: Dynamically make object/field required if another field is !=NULL
          Steve L Walker Level 5

          Justin,

           

          There are several ways to approach this. In my example I added the following JavaScript on the change event of the RadioLocation radio button exclusion group. If the user selects 'No' (rawValue '2') I reset the drop-down list, in the event it contains a value, and I disable access to the drop down. If the user selects 'Yes' (rawValue '1'), I make the drop-down available (or "User Entered - Optional").

           

           

          // form1.#subform[0].RadioLocation::change - (JavaScript, client)

           

          if (RadioLocation.rawValue == "2") {

               DropDownList2.rawValue = null;

               DropDownList2.access = "protected";

          }

          else {

               if (RadioLocation.rawValue == "1") {

                    DropDownList2.access = "";

               }

          }

           

          On the drop-down list I add a script to check if the selection is null. If it is null and RadioLocation is 'Yes' (rawValue '1'), I put up a message box,

           

          // form1.#subform[0].DropDownList2::exit - (JavaScript, client)

           

          if (DropDownList2.isNull && RadioLocation.rawValue == "1") {

               xfa.host.messageBox("If 'Other Locations' is 'Yes', please select the # of locations.");

          }

           

          Note. I you want to enforce the validation before printing or submitting you will need additional script against the applicable events.
          Steve
          1 person found this helpful
          • 2. Re: Dynamically make object/field required if another field is !=NULL
            ndjustin20 Level 1

            Good Morning Steve,

             

            I took a look through your code and example and really appreciate the advice!!!  The only problem that remains is two fold.  Right now if you select yes and don't click on the drop down you can totally bypass the code altogether plus I can submit or print the form without the necessary information.  Is there a way to change the validation property of an object to run the <validate nullTest="error"/> and have it return the adobe required error when you try to submit, save, or print?  OR is there a way to add a global variable to each object and test for it each time, with a different error message for each object, each time you try and submit, save, or print?

             

            I want to also say that I am learning alot by your help and greatly appreciate the advice thus far and any feedback or assistance in the future is again greatly appreciated.

             

            Also, if you know of any really good tutorials out there on livecycle form programming please point me in the right direction as I'm brand new to the program and really like the ease of use by my counter parts and the RAD process is awesome

             

             

            Justin