5 Replies Latest reply on Mar 24, 2009 10:14 AM by (BJF)

    Required Fields based on field value

    (BJF)
      I am using Acrobat 9.1 Std. This is what I am trying to accomplish I have four text fields that I want to make required based on the selection of a radio button group.
      I have two radio buttons on the form w/ the same name w/ the button value set to Yes for one and No for another. If the radio button w/ value Yes is selected I want to set the four text fields to required. If the radio button value is No the text fields should be optional.
      Ive found similar postings for what I am trying to accomplish; however, I havent had any success in getting it to function correctly.
        • 1. Re: Required Fields based on field value
          (BJF) Level 1
          Some more information on what I have tried..For simplicity Im just trying to get one text field to work, then I can repeat the java code for the other text fields.
          In acrobat Standard 9.1 I go to Forms Add or Edit Fields from there I select the radio button group (contains two radio buttons) on the left column and select properties. Then on the radio button properties dialog box I select the Actions tab. Set the Trigger for Mouse Up and the Action for Run a JavaScript . I click the Add button and enter the following into the JavaScript editor:

          if (this.rawValue == "Yes") {
          TextField1.validate.nullTest = "error";
          xfa.layout.relayout();
          }
          else {
          TextField1.validate.nullTest = "disabled";
          xfa.layout.relayout();
          }

          I then close the JavaScript editor, save the form and re-open to test it. I select the radio button w/ value Yes and click the Submit button and the form goes on to submit. At this point I would expect it to error because I didnt fill in any value for TextField1.
          I also tried altering the field tag with the below java:

          if (this.rawValue == "Yes") {
          TextField1.mandatory = "error";
          xfa.layout.relayout();
          }
          else {
          TextField1.mandatory = "disabled";
          xfa.layout.relayout();
          }

          This also didnt work. Im not sure if I am using the correct tag or not or why I am unable to get the text field to become required for submission.
          Any help would be greatly appreciated.
          Thanks,
          • 2. Re: Required Fields based on field value
            Patrick Leckey Level 3
            You are working with AcroForms (based on your description of how you are adding form fields), but some of the JavaScript you are calling is specific to XFA Forms (which are created in LiveCycle Designer). These two types of forms are not interchangeable and neither are their JavaScript methods.
            • 3. Re: Required Fields based on field value
              (BJF) Level 1
              Thanks PDL,
              I downloaded the AcroJS.pdf file and came up with the following:

              //my radio button group is named RequestType and the Text
              //field I want to require based on
              //selection is name HireDate

              var hdate = this.getField("HireDate");
              var request = this.getField("RequestType");
              if (request.value == "Yes") {
              hdate.required = true;
              }
              else {
              hdate.required = false;
              }

              The above appears to be working; however, it would be nice to know from a guru that the above syntax is correctly done.
              • 4. Re: Required Fields based on field value
                Patrick Leckey Level 3
                The above is correct JavaScript syntax. Can't validate it in terms of the PDF it's running on without seeing the PDF, but if it's doing what you want without throwing any errors chances are there are no problems.
                • 5. Re: Required Fields based on field value
                  (BJF) Level 1
                  Thanks again PDL,
                  Truely appreciate your help.