8 Replies Latest reply on Aug 4, 2011 8:31 AM by MarkWalsh

    resetting hidden fields on 'Clear Form'

    MarkWalsh Level 4

      I have a form which changes the display values of certain fields (or may set them to readonly) when different options are selected. I have provided a 'Clear Form' button which runs a javascript that resets these fields to their original state, but users have always been able to select 'Clear Form' from the menu, which bypasses the script and can leave the form in a non-logical state.

       

      Is there any way to prevent the 'Clear Form' menu from being selected, or to override it's function, or to run one of my functions when it does? I have never had a chance to find a solution, and this form will need to be reset properly under all conditions that a user can encounter.

        • 1. Re: resetting hidden fields on 'Clear Form'
          George_Johnson MVP & Adobe Community Professional

          Whenever you set the value of the hidden/readonly fields, set its default value to the same thing. You can do this automatically with a custom Validate script:

           

          event.target.defaultValue = event.value;

           

          So when the form is reset via the menu, the value won't change.

          • 2. Re: resetting hidden fields on 'Clear Form'
            MarkWalsh Level 4

            I'm sorry, I think I wasn't clear. It's not the values of the fields I need to change. I'm hiding the fields by setting the display.visible/display.hidden properties when a checkbox is selected. When the user selects 'Clear Form', the checkboxes are cleared, but the fields which they may have hidden (or made visible) are still hidden/visible.

             

            From what I can see, it doesn't sound like there is any way to 'reset' the form if the user clears the form via the menu.

            • 3. Re: resetting hidden fields on 'Clear Form'
              George_Johnson MVP & Adobe Community Professional

              I see. What I suggested would cause the "Clear Form" menu item to not have an effect. I thought this may have been what you wanted since you mentioned you were looking for a way to prevent it from being selected.

              • 4. Re: resetting hidden fields on 'Clear Form'
                George_Johnson MVP & Adobe Community Professional

                Mark,

                 

                How about something like this. Set up a hidden field that when cleared executes your reset routine. I believe that the last field that was added is the last field to get reset. You could initialize its value and call your reset routine in its Validate event if its value is blanked, and then reject the change so it doesn't actually get cleared.

                • 5. Re: resetting hidden fields on 'Clear Form'
                  MarkWalsh Level 4

                  Ok, then maybe I misunderstood what you were saying. I'm not sure if setting the 'default value' of the fields would be what I want to do, but I'll check to see how/if that would work in my situation.

                   

                  The idea of a field running the code when updated is an interesting idea as well, assuming it may or may not work. I'll look into this further. Perhaps setting up a calculated field which resets things might work, but I'll have to check the ramifications of this method.

                   

                  Thanks for the suggestions

                  • 6. Re: resetting hidden fields on 'Clear Form'
                    George_Johnson MVP & Adobe Community Professional

                    Feel free to ignore my first suggestion, it won't work well for a complicated form, especially one with non-text fields. The other approach should work just fine and be easy to implement.

                    • 7. Re: resetting hidden fields on 'Clear Form'
                      maxwyss Level 4

                      Besides hiding the menu bar, I am not aware of any other options to prevent users from using the menu command.

                       

                      The workaround is psychology, by providing the user a big very visible button "RESET", plus instructions to use that button, or else…

                       

                      That button then calls a function which resets the form, but also creates a proper initial state of the form (which would contain colors, readonly, display properties etc.).

                       

                      The suggested hidden calculation field should however work reasonably well. You'd have to figure out the conditions under which the initial state can be set (essentially all relevant fields having the same value as their defaultValue).

                       

                      Hope this can help.

                       

                      Max Wyss.

                      • 8. Re: resetting hidden fields on 'Clear Form'
                        MarkWalsh Level 4

                        It looks like the calculated trigger field may do what I want. I set up a field with the following calculation code:

                         

                        if (event.target.value == event.target.defaultValue) {

                              // run my trigger Reset code here

                         

                             // Clear trigger value

                              event.target.value = ""

                        }

                         

                        The defaultValue of the 'trigger' field is 'Reset'

                         

                         

                        So far, this looks like it works well, thanks muchly!