Announcement

Collapse
No announcement yet.

Preventing loosing change

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

  • Preventing loosing change

    Hi,
    is ther an option to warn a user that he has to save data of his form before leaving in case he has modified some field ?
    Actually, if the user forget to click the save button, all changes are lost when leavin the page and no message is shown indicating that he has made change.

    Thanks

    Sylvain

  • #2
    Since the input of the screen is done on the client side (The browser) the main php application is unaware of that. So I think it should be possible, but you have to dive into the Javascript world. I guess that if you use Ajax onchange events you could achieve something similar so I would try this with a small screen of three fields or so. But this is not behaviour out of the box.
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

    Comment


    • #3
      This is an old Thread. we are waiting for that. http://www.scriptcase.net/forum/show...r-save-changes

      Comment


      • #4
        Thanks for the responses.
        @alvagar so you have no news on that ??
        Saw that your request is from 2013 !
        These kind of thing is an essential feature in my opinion...
        They don't seem to react quickly at scriptcase.

        Comment


        • #5
          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...

          Comment


          • #6
            @ HakLin0816
            Thanks

            Will see because on my form, there's more than 100 fields, so binding an onChange event on each will be fastidious.

            Thanks for your response

            Sylvain

            Comment


            • #7
              Good ... Like +1

              Comment


              • #8
                One can expand browser compatibility by changing OnApplicationInit code like this:

                Code:
                //Close PHP
                ?>
                <script>
                var Haschanged = 0; 
                if(window.addEventListener)
                 window.addEventListener('beforeunload', function( event ) {if(Haschanged == 1) event.returnValue = 'Message to display when leaving';});
                else
                 window.attachEvent('beforeunload', function( event ) {if(Haschanged == 1) event.returnValue = 'Message to display when leaving';});
                </script>
                <?php
                //Reopen PHP

                Comment

                Working...
                X