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

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

    I've created a button that prompts the user if they want to save changes. The function for the alert doesn't return anything, so if you click cancel, it just goes back to the form. If you click ok, it updates the table, and redirects to another page. I tried the function sc_exit(c), but this doesn't seem to do what I want. Instead of all this, is there any default button I could use, or something else to do this instead of writing my own code?

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

    Have a look at sc_confirm() and use them in your own buttons, or place them in any required event.
    'No' cancels the activity.

    Regards,
    Scott.

    Comment


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

      I have used sc_confirm but it doesn't seem to return a value, so I don't know if the user clicked ok or cancel, like you said in another post, if their documentation was a little better, I wouldn't be here asking these somewhat silly questions. If sc_confirm does return something, what is it?

      Comment


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

        also, is there an onExit() event, or would I have to do that with JavaScript or AJAX?

        Comment


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

          You could use JS/Form/onSubmit and add:
          return confirm('Are you sure?');

          That would trap the Update button, but not the cancel. Myself I would not trap cancel if not changed.
          You can trap a field change using sc_changed(field), but you will have to check each field. You may want to compare before after record buffer in there is this option instead of checking each field for a change.

          You could also use in JS:

          myfunction();
          return myfunction() instead of confirm to get better control.

          There is also AJAX where you could trap onClick

          Regards,
          Scott.

          Comment


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

            On thing that will about regarding the help is to search the net like you are not using SC and just you are using PHP, JS, AJAX and search for what you are trying to achieve. Once you get the answer, then determine how you are going to get SC to perform this and usually you will find you can move forward. I consider SC my shortcut tool, but use the net to learn how things are done.

            Regards,
            Scott.

            Comment


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

              im not a novice, and i do know a good amount, it's SC that is tripping me up because of the documentation. I don't get how some of the things work in SC. My question about what you just said is, if I put
              Code:
              return confirm('Are you sure?');
              in JS/onSubmit part, where does that return value go, where do I check it to see whether they clicked ok or cancel?

              Comment


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

                As mentioned, you can have more control using your own function instead of using confirmed().

                Something like:

                Code:
                function myconfirm() {
                 var is_confirm = confirm("Are you sure?");
                
                 if (is_confirm) { return true; } else { return false; } 
                
                }
                
                return myconfirm();

                Comment


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

                  To further this, you may have perform this in AJAX, as the above code determines this if the OK was pressed and checks the answer, not if you click the cancel button in the form itself (I am slow sometimes

                  (See below instead of using AJAX)

                  Regards,
                  Scott.

                  Comment


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

                    Yes... I created a new JS button and added the code I presented in myconfirm and it worked. You will then have to handle the mysql calls (if any) yourself and drop the Exit/Cancel buttons from the toolbar.

                    Regards,
                    Scott.

                    Comment


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

                      i need to use php to do the SQL calls, so how would i be able to get the return value from the javascript function into php?

                      Comment


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

                        First, I just want to say thanks for all your help. I would still be stuck on my other problem if it wasnt for you. I've taken your advice and I've been looking on the net for a solution to this problem. I just need to get more familiar with the inner workings of scriptcase. If you could answer me this though, how do you do this?
                        You may want to compare before after record buffer in there is this option instead of checking each field for a change.

                        Comment


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

                          Well... a function from another library (win32) must have run over into my head when I commented on this.

                          In a db I used to use, they maintain a record buffer for this. I suspect this would be easy to mimic in code.

                          The only way I can see built into mysql is to use NEW/OLD in a trigger. As for SC, it seems you would have to create function using sc_changed for all fields, or go a little lower level and populate a PHP array on load and in onValidate compare the fields to that array, or something like that.
                          I was hoping for a sc_record_changed, but it does not exist.

                          Regards,
                          Scott.

                          Comment


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

                            Hi Guys,

                            If I understand you guys correctly, there's no (standard) way in Scriptcase to check if data in a form has been changed other than check this for each field seperately?

                            Is there however a (standard) function/macro to save all unsaved data in one action? if so, does this solve your problem or not?

                            Comment


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

                              if there is a function to save all the fields, then I would like to know. right now I'm using a SQL UPDATE statement to save the changes to the record.

                              Comment

                              Working...
                              X