5 Replies Latest reply on Feb 13, 2014 11:35 AM by philmodjunk

    Cancel window close

    CraigAlderson

      Title

      Cancel window close

      Post

           Working with FM 11. I have a window with a list of records. Users can't go into the fields directly to edit them. They must click a button to edit the data in a particular record, and that data is copied to a set of global fields, where it can be edited. To save the changes, users must click a "Save" button. This allows me to test the data to make sure it's complete before copying it back into the record and committing it.

           What I want is to deal with closing the window when edits have been made but the Save button hasn't been clicked. I want a "You have unsaved changes. Continue?" dialog box. The global fields have a variable OKtoExit that is set to false by the field's OnObjectModify event. The window has a Close button that will prompt with the unsaved changes/exit dialog box if OKtoExit is false.

           A few problems: 1) I can't stop the window from closing. If someone chooses "don't close" on the unsaved changes dialog box (i.e., continue editing), the window closes anyway. How can I fix this? 2) I can't cancel the close if someone clicks on the X in the window frame either. I can get the dialog box, but then same problem as in #1. 3) I get the unsaved changes dialog box twice if I click the Close button, but not when I click the X. It's obviously being triggered by the OnLayoutExit event, but I can't figure out why it's being triggered twice.

           Any better way of handling this?

           Thanks,

           Craig

        • 1. Re: Cancel window close
          philmodjunk

               Since the data is in global fields, can't you just use new window re-open the window in order to "cancel the close"?

          • 2. Re: Cancel window close
            CraigAlderson

                 Hmm. Possible but not desirable. The global fields and variables are initialized when the window opens, so that data will be lost. Isn't there a way to cancel the close event itself? Thanks.

            • 3. Re: Cancel window close
              philmodjunk

                   That depends on how you set up the action to close the window. and "The global fields and variables are initialized when the window opens," is something that you can modify so that this isn't driven by a script trigger on that window's layout.

                   A button to close the window can check before closing the window. And a custom menu where you have replaced the close window menu option--which is what is selected when you click the "close window" control in the corner of the window--that replaces the normal menu option with the same script can ask for user confirmation.

                   But you can't do this from the OnWindowCloseTrigger as the script is performed After the window close event is processed, so it's already too late by the time your script starts up.

                   See "Setting up Script Triggers" in FileMaker help to see a table of all script triggers and which ones are "before the event" triggers and which are "after the event" triggers. Only "before" triggers can use Exit Script [False] to cancel out the triggering event.

              • 4. Re: Cancel window close
                CraigAlderson

                     "The global fields and variables are initialized when the window opens," is something that you can modify so that this isn't driven by a script trigger on that window's layout.

                     How would I do this?

                     I'll check out the help files for the event trigger sequence. Thanks for the tip.

                • 5. Re: Cancel window close
                  philmodjunk

                       Presumably, you are performing a script to open the window in the first place. This script can include set field steps to clear the fields.

                       I frequently set up one script for opening such a window with a script parameter such that if Get ( ScriptParameter ) = "Clear", the script clears the fields. If it is not, it leaves them with current values. This allows me the option of re-opening the window without clearing the data. This is useful in some of my "Find record dialogs" as a find button can perform a script to open the window with the "clear" parameter and a Modify Find button can perform the same script to open the same window but without the "clear" parameter and then the user is able to modify the values in the fields without having to re-enter.