Announcement

Collapse
No announcement yet.

Can you make a form prompt the user to save changes when they exit?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Re: Can you make a form prompt the user to save changes when they exit?

    Sorry I jumped in this discussion withoud reading the whole thread.... But could you please clarify what your goal is, what do you want to achieve? (from a user perspective).

    Are you (like me) looking for a way to alert the user that there are unsaved changes when the user hits the exit, cancel or close window buttons?

    Comment


    • #17
      Re: Can you make a form prompt the user to save changes when they exit?

      What I want is, is a prompt that asks if the user wants to save changes made, to pop-up when the user clicks the exit button. I don't think there is anything built-in, so I am trying to do it myself with code. I'm close, but I still haven't gotten it to work. I'll let you know if I do get it too work.

      Comment


      • #18
        Re: Can you make a form prompt the user to save changes when they exit?

        I hope the developers of SC read these forums, I thought I had this problem fixed, but it still isn't. If the 'sc_confirm()' function actually returned a value, then this would be a simple solution. I don't see what the point of having this function not return a value. Maybe this is something they can fix...

        Comment


        • #19
          Re: Can you make a form prompt the user to save changes when they exit?

          Alright, I figured it out, and it ended up being a simple solution. I know it would've helped me alot if someone else posted this before so here is the code I ended up with. I tried so many different things and this is what I ended up with, I made a javascript button, and added this code:
          Code:
          var ans = confirm("Would you like to save your changes?");
          if(ans == true)
          {
          	nm_atualiza('alterar');
          }
          You would need to add a check for all the fields to see if they've been changed, but this prompts the user and if they click 'Ok' then it calls a function that updates the record. I knew there had to be a function to do this instead of writing my own code. Also, you would need to add the 'else' part to check if they clicked 'Cancel'.

          Comment


          • #20
            Re: Can you make a form prompt the user to save changes when they exit?

            vivid, your code works fine. What I want however goes a bit further, but I cannot get it to work. Maybe you, or anybody else, can help?

            Here's what I want:
            A button with label "Exit Form" on a simple form. When pushing this button the following code should be executed (in pseudo code):

            Code:
            if one or more form fields have been changed on the client
            then
             ask user if he wants to save changes
             if he chooses yes, save and exit form
             else exit form
            else (no form fields have been changed)
             exit form
            end if
            I took your piece of code and added code using sc_changed and sc_exit, but it doesn't work as I hoped for. sc_changed doesn't work at all, and sc_exit only works in php buttons according to documentation.

            Can you help me? I need to do a demo on this next saturday.....

            Comment


            • #21
              Re: Can you make a form prompt the user to save changes when they exit?

              The short answer. There is no built in function.

              This answer can be simple or get real involved. The simple answer is that when on onChange/onClick event happens, you can set a variable and call confirm if that variable is true. There is no guarantee that the user did not revert the data back. In this case, you are still safe as they have made some changes, but they reverted back, hence a prompt.

              Another approach perhaps is to show the record in VIEW only mode first (all fields are labels). Create a button called edit. that loads another form identical, but all fields are in edit mode. If they click update, prompt and save.

              This helps in several ways, as it allows user to view the record. If they edit, then they get a prompt (if an onchange/onclick was triggered) and save the record.

              If you are bent on showing a prompt only if the data is different on save, then you will have to write your own array function to compare the fields at time of load from the fields in the client form that are about to be saved. (also taking to consideration that perhaps another user has loaded and saved the data on another pc) This is were it gets more complicated... research triggers, etc.

              Regards,
              Scott.


              Comment


              • #22
                Re: Can you make a form prompt the user to save changes when they exit?

                Can/must it be done using a javascript button? if so, how can I access the array you propose from javascript?

                You don't mention sc_changed. In what cases is this function useful?

                Comment


                • #23
                  Re: Can you make a form prompt the user to save changes when they exit?

                  sc_changed is based on the field has changed. You would have to write a function to cycle all fields to use this.

                  You should not have to create a separate button for this.

                  The array is something you would have to create in code. Then you could compare right away instead of having to check in the onBeforeUpdate using sc_changed for each field.

                  You could create/populate the array on form load, and compare the form fields with the another array (2nd array based on form fields) on onValidate.

                  I suggested the array approach as you can compare arrays easily. You can also use another approach if you wish.

                  To check for changes of any fields, you will need to create your own function unless SC creates one for you.

                  Regards,
                  Scott.

                  Comment


                  • #24
                    Re: Can you make a form prompt the user to save changes when they exit?

                    I am disappointed that this feature is not a standard option in SC.
                    I will try a technique I have used in other systems.
                    For all form fields, in the onfocus event, store the value of the field into a tmp variable.
                    In the onblur event compare the field value to the tmp variable.
                    If it does not match set a global variable called, say, "UnSavedData", to yes.
                    Replace the exit button and all of the navigation buttons with your own buttons.
                    Program these buttons to display a warning message and dialog box if the global variable is yes.
                    Take appropriate action based on the user input in the dialog box.

                    Please, please add this feature in the next version
                    and please tell me that multi-user integrity is already built in.

                    pmjenck@gmail.com

                    Comment


                    • #25
                      Please, please add this feature is very important. is possible?

                      Comment


                      • #26
                        My solution to alert the user when data is not saved:

                        Add this in onApplicationInit event of the form:
                        echo "<script>var Haschanged = 0; window.addEventListener('beforeunload', function( event ) {if(Haschanged == 1) event.returnValue = 'Message to display when leaving';});</script>";

                        Add javascript for Form->OnSubmit so there will be no prompt if the record is saved:
                        function sc_form_onsubmit()
                        {
                        Haschanged = 0;
                        }

                        For every field that you want to "monitor" add javascript Field->OnChange
                        function sc_MyField_onchange()
                        {
                        Haschanged = 1;
                        }

                        You will now get an option to leave or stay on the page if any of the "monitored" fields has changed...

                        EDIT: This post was supposed to be in another thread :S
                        But it fits well here to...
                        Last edited by HakLin0816; 11-27-2014, 07:39 PM.

                        Comment

                        Working...
                        X