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

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.

This is an old Thread. we are waiting for that. http://www.scriptcase.net/forum/showthread.php?4246-functionality-for-save-changes

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.

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…

@ 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

Good … Like +1

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


//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

Hello,
thanks for your hints.
I’m not a programmer and I got some difficult to understand the script.
I inserted all things as you suggested but I got still an error that I don’t know how to fix.
Parse error: syntax error, unexpected ‘?’ in C:\Program Files\NetMake\v9-php73\wwwroot\scriptcase\app\Pipeline_Management\form_pipeline_entry\form_pipeline_entry_apl.php on line 619

This is the edit of file code
{
$_SESSION[‘scriptcase’][‘form_pipeline_entry’][‘contr_erro’] = ‘on’;
echo ??;
$_SESSION[‘scriptcase’][‘form_pipeline_entry’][‘contr_erro’] = ‘off’;
}
$this->Ini->init2();
}

Can you help me on fixing it ?
Thanks
Giò

I changed OnApplicaionInit content also with the code of [HakLin0816] . No errors but nothing happens when I leave the form.
"

Have you tried to set at TRUE the flag Notify discarded changes in the Layout and Behavior section of the form settings.

Hello,
yes I did it. Still no warnings …

The previous button content to leave the form is this one but I don’t think it’s wrong.
It a simple redir

if (’[glo_limited_view]’==“Y”)
{sc_redir(grid_pipeline_limited);}
else
{sc_redir(grid_pipeline);}