We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8822
    • 203 Posts
    Hey, does anyone know how to go about displaying an extra field in a FormIt Form if a certain option is selected in a dropdown. For example, if 'Dog' is selected from the drop down 'Animal' a text box for the Dog Breed is displayed adjacent to it (or beneath)?

    Similary, is it possible for FormIt to display another row (of say 3 specified fields), if the first row is filled in. For example, adding 'additional people' to a list - if one person is added then another row appears for the user to be able to add another person (and then another etc. etc.)

    Using Revo

    Thanks for any pointers smiley
      • 19369
      • 1,098 Posts
        • 39436
        • 3 Posts
        First of all thanks so much for pointing out these examples. I too am looking to solve the very same problem in formit. Demo 1 from http://kotowicz.net/jquery-option-tree/demo/demo.html is exactly what I would be looking for, however, can anyone demonstrate what the code would look like for that in formit? I really need to see a working example in order to implement it. Thanks!
          • 19369
          • 1,098 Posts
          There are several examples there, can you explain in details what you want to accomplish?
            • 39436
            • 3 Posts
            I want registrants (members of certain congregations) to be able to drill down to their particular congregation via this form in order to register for this event. So the first options would ask what Conference are they from (Conference 1, Conference 2, etc.)? The Sub-options would ask what Circuit are they from (Circuit 1, Circuit 2, etc.)? The Subsubs would ask what congregation are they from (Congregation 1, Congregation 2, etc.)? Upon selecting their congregation, I want them to access a unique registration form for their congregation, either via a link but ideally calling a snippet. What do you think? I really thought I might find an example of this somewhere, but can't.
              • 19369
              • 1,098 Posts
              I see, I think that optionTree plugin will do what you want then. You can put a Resource id for the values on the right and redirect the page to the form you want, or maybe can open a iframe with colorbox with the form on it, so the user doesn't need to change page.

              At the end of the script you need to add something like "location.href = this.value;" to make it change page, here is an example of what I did on a website some time ago:

                  
              $(function() {
                 var option_tree = {
                   [[!Wayfinder? &startId=`[[UltimateParent]]` &level=`2`]]
                  };
                  var options = {empty_value: -1, choose: 'Select Category'};
                  $('input[name=dropdown]').optionTree(option_tree, options)
                  .change(function() { if (this.value != -1) { location.href = this.value; } });
              });
              
                • 39436
                • 3 Posts
                This will seem remedial to some, but with such a broad range of skills looking at this forum, I know there must be others like me who struggle with the basics. Here is perhaps not the elegant solution that Emily was looking for in formit, but using some Javascript, a way to "get there."

                The problem is stated above. I used Demo 1 from http://kotowicz.net/jquery-option-tree/demo/demo.html. I needed two files (attached) to be uploaded to my server. I referenced these two files in my revo template for my site (in the head section). Make sure to change them from .txt to .js files in your favorite text editor before you upload them.
                 
                <script type="text/javascript" src="assets/.../js/jquery-1.3.2.min.js"></script>
                <script type="text/javascript" src="assets/.../js/jquery.optionTree.js"></script>
                


                What follows is the working example of the code. I needed a foolproof way for registrants to register for an event by their congregational ID# which is largely unknown to the registrant. The result produced by the optionTree directs the registrant to a personalized form (not sure whether that will be a new page or another solution yet) based upon the database key. Hope this helps and thanks so much to microcipcip for guiding me to this solution!
                <label for="findUnitID">Find Your Congregation ID Number</label>
                
                <input type="text" name="findUnitID" />
                <script type="text/javascript">
                $(function() {
                   var option_tree = {
                       "Option 1": {"Suboption":200},
                       "Option 2": {"Suboption 2": {"Subsub 1":201, "Subsub 2":202},
                                "Suboption 3": {"Subsub 3":203, "Subsub 4":204, "Subsub 5":205}
                               }
                    };
                 
                   $('input[name=findUnitID]').optionTree(option_tree)
                 .change(function() { if (this.value != -1) { location.href = this.value; } })
                });
                </script>
                
                [ed. note: webrev last edited this post 14 years, 6 months ago.]
                  • 32316
                  • 387 Posts
                  I think it bears mentioning again: (quoting from the formIt docs)
                  FormIt is a dynamic form processing Snippet for MODx Revolution. It handles a form after submission, performing validation and followup actions like sending an email. It does not generate the form, but it can repopulate it if it fails validation.
                  and again:
                  It does not generate the form.

                  Also if you are creating a new form using jQuery may I humbly suggest that using the latest version which is as of right now 1.7.2 is a good idea! [ed. note: whistlemaker last edited this post 14 years, 6 months ago.]
                    • 8822
                    • 203 Posts
                    Hi everyone, thanks for all your comments and help. I am currently working on the easiest of the two functions described above (simply displaying an extra input field for Breed, if the option 'Dog' is selected from a dropdown). I've hidden the field dogbreed and then added a 'onchange' to call to the select dropdown which will display the hidden field if 'Dog' is selected (still with me?!!). This works great until the validation stage - if submit is pressed and there are other required fields that have not been filled in correctly on the form, the page reloads but hides the dogbreed field again - whats the best way to recall the 'onchange' function again after the submit button has been pressed and retain any information that may have been entered in this field?