4 Replies Latest reply on Jan 5, 2011 7:03 PM by virtual_alicia

    Scripting for Required Contingent Questions?

    virtual_alicia

      I have a form with a table, and depending on the answer selected in the left-most column, which is a dropdown menu, fields in the will become required.  Sounds confusing when I read this, but what I mean is if someone selects YES from the dropdown menu for rows1 and 2 and NO for 3-6, then the rest of the fields in rows 1 and 2 become required and text has to be added or dropdown menus have to have a valid answer selected while the rest of the table does not.

       

      The table looks like this:

        Order book?    Author  Title    ISBN\Publisher    Total Requested  Readopt?   Required?

        (Dropdown Y/N)  (Text)   (Text)  (2 Sep. Text Fields)   (Text)     (Dropdown) (Dropdown)

      1.

      2.

      3.

      4.

      5.

      6.

       

      The answers become required in the sense that they have to be filled out before the form can be submitted, and not in the sense that one answer can only be filled in if the previous is answered.  It might be too much for the people filling out the form to have to make sure the previous field is entered before moving on to the next one.  The entire table is visible already, so I don't need the fields to become visible upon selecting YES, although I see the benefit in this too.  Can I have the scripting formulas for both, like, can I make the fields become visible upon selecting YES (so text can't be entered if they select no) and required to fill in before submitting?

       

      Oh, another thing I'd like to do is make 1 selection from a dropdown menu not valid.  I have a list of **, YES, and NO.  I want to make the ** not recognized as a valid response.  Thanks for your time and patience.  I realize this question probably belongs in the Scripting forum, so I'll add it there too.

        • 1. Re: Scripting for Required Contingent Questions?
          George_Johnson MVP & Adobe Community Professional

          If you use a field naming convention that places a row identifier at the beginning of the field name, you can do what you want with a single statement in the Validate event of the column 1 combo box. For example, if the field names for the row are:

           

          row1.author, row1.title, row1.isbn, row1.publisher, row1.total, row1.readopt, row1.required

           

          The following code can be used as the combo box's Validate script:

           

          // Validate script for the column 1 combo box

          getField("row1").required = (event.value !== "**");

           

           

          Set up the combo box options so that "Commit selected value immediately" is selected.

           

          You can then use a similar script for the other combo boxes in the other rows. If you stick to the row1, row2, row3, naming convention, you can create a single document-level function that can be called from all of the combo boxes:

           

          function setRequired() {

           

              // Get the row ID, which is the fourth character of the field name that called this function

              var num = event.target.name[3];

           

              // Set the required property of the other fields on the row

              getField("row" + num).required = (event.value !== "**");

           

          }

           

          and call this function like this in the combo box's Validate event:

           

          // Validate script for the column 1 combo box

          setRequired();

           

           

          The problem is setting the required value of a combo box (readopt, required), since a combo box always has a non-blank value, unlike a text field. So a better way to handle this is to create a script that scans all the fields in all the rows and checks for completeness. This allows you to create a more user friendly error message and can handle required combo boxes. Post again if you need more help with this approach.

          1 person found this helpful
          • 2. Re: Scripting for Required Contingent Questions?
            virtual_alicia Level 1

            Thanks George.  The first script works great.  Where does the second script go, in the debugger?  I'm assuming this is the script that checks for completeness, yeah?

            • 3. Re: Scripting for Required Contingent Questions?
              George_Johnson MVP & Adobe Community Professional

              If you're asking about the "setRequired" function, it is intended to be added to the document as a document-level function. To create one, select: Advanced > Document Processing > Document JavaScripts

               

              Add a new one, giving it any name you like, delete the function skeleton it provides by default, and past the function code shown above. You then call the function as shown.

               

              If you're asking about what I was discussing the the last paragraph, that would be a new script that checks the fields before the submit is allowed to take place. I did not provide the code for that. It too would be a document-level script.

               

              Also, you should consider what to do if the user select Yes or No, completes the rest of the row, and then later has a change or heart and selects "**". It seems like it would make sense to clear the values on the other fields of the row, but the script does not currently do this. If you'd like it to and get stuck, post again.

              • 4. Re: Scripting for Required Contingent Questions?
                virtual_alicia Level 1

                I did get stuck with trying to remove entered text when the value changes from

                Yes to No.

                 

                Also, I wrote the script for ** to not count as an option, but it left No as a value that made the rest of the fields required.  Basically, I can create a script to exclude one option, but I need a script that either excludes teo options (No and **) or includes 1 option (Yes).