I’m trying to disable autosave feature of Servoy.
I’d like to add a “save” button on my forms and let the use
choose if save or cancel his changes.
In my start method i put:
application.setFocusLostSaveEnabled(false)
The problem is this seems to be ignored.
When the user edit a record and close the form without pressing
“save” button, all changes are committed.
Ad it seems to me the changes are commited even on lost focus
of fields.
Transactions may be the thing to resolve your issue.
If you look at the Database Manager node of the Method editor you will find several items covering Locking records and handling transactions :
Start, Commit & Rollback
You can create a method and attach it to the ‘onRecordEditStart’ property of the form which then controls your whole editing sequence.
Thanks, I know about transactions.
I would like a simplest method to do a very simple thing.
Transactions could be more usefull when multiple table updates are involved.
I think if application.setFocusLostSaveEnabled(false) could work
this is the simplest thing.
Well, with the ‘application.setFocusLostSaveEnabled(false)’ command you also have to use it in conjunction with the ‘controller.saveData()’ command to somehow commit your data !
I think (i’m not sure) but the function: 'application.setFocusLostSaveEnabled(false)
works only for fields on the form. So if you leave a field, or click besides the field, the changes will NOT be saved.
Sorry, but I’m new to Servoy so sometimes I use terms not appropriated. With “close the form” I simply mean “activate
another form” but I guess this is not appropriate for Servoy.
What I would like to do is not to commit changes to the database if the
user doesn’t press “save” button. This on all forms of my application!
By now I have just an edit form so we can speak of this form only.
I tried to put application.setFocusLostSaveEnabled(false) in the startup
method of my solution, so I expect any changes are wrote if the users
doesn’t press “save”. Of course in the method associated to “save” I call
controller.saveData().
I done some tests and what I see is this:
When the user add a new record, this is wrote to database even if “save” is not pressed, so the record appears to other users
When the user changes data in a record, the data is not wrote while
the user is on the same form, but when another form is activated then
data is wrote even if “save” is not pressed
I don’t want nor 1) neither 2). I would like new record is added and data
is wrote only if user choose to save data.
I think I need even something to revert all edited fields to original values
if the user chooses to discard changes.
I agree with Harry Catharell, I think transactions can be a really easy and powerfull way to solve your problem, even if only one table is involved.
Just fire a databaseManager.startTransaction() when you show your form and then databaseManager.commitTransaction() when you want to save changes (on save button) or databaseManager.rollbackTransaction() when you want to ignore them (on hide form or undo button)
I admit that I have not used the setFocusLostSaveEnabled() function in earnest.
But I would guess that if you were also trying to use it in conjunction with a new record control then it would not handle Rollback in the same way that Transactions would and that the steps involved in invoking the function and trapping for it and then using saveData() or reverting the record state would be just as ‘simple’ as using Transactions !
That said, I would like some ‘scope’ details myself regarding the function as if it exists then I would like to know the relative merits of using it versus using Transactions - so if anyone would like to chime in then please feel free !