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

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.

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?

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.

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

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

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…