setFocusLostSaveEnabled(false) not working?

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

setFocusLostSaveEnabled(false) not working?

Postby a.mariottini » Tue Sep 21, 2004 5:42 pm

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.

Servoy 2.1 build 310 on MacOS X
Andrea Mariottini
a.mariottini
 
Posts: 120
Joined: Mon Aug 30, 2004 9:20 am
Location: Macerata, Italy

Postby Harry Catharell » Tue Sep 21, 2004 5:59 pm

Hi Andrea,

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.

Cheers
Harry
Harry Catharell
 
Posts: 812
Joined: Fri Sep 26, 2003 10:23 am
Location: Milton Keynes, England

Postby a.mariottini » Tue Sep 21, 2004 6:31 pm

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.
Andrea Mariottini
a.mariottini
 
Posts: 120
Joined: Mon Aug 30, 2004 9:20 am
Location: Macerata, Italy

Postby Harry Catharell » Tue Sep 21, 2004 6:38 pm

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 !

Could this be where your problem lies ?

Harry
Harry Catharell
 
Posts: 812
Joined: Fri Sep 26, 2003 10:23 am
Location: Milton Keynes, England

Postby a.mariottini » Tue Sep 21, 2004 6:59 pm

No, my problem is changes are commited even if I don't call controller.saveData()!!!
Andrea Mariottini
a.mariottini
 
Posts: 120
Joined: Mon Aug 30, 2004 9:20 am
Location: Macerata, Italy

Postby Harjo » Tue Sep 21, 2004 8:21 pm

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.

It is not build for leaving the form.
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Postby a.mariottini » Wed Sep 22, 2004 9:12 am

Could Servoy team clarify the use and the "scope" of application.setFocusLostSaveEnabled(false)?
Andrea Mariottini
a.mariottini
 
Posts: 120
Joined: Mon Aug 30, 2004 9:20 am
Location: Macerata, Italy

Postby Harry Catharell » Wed Sep 22, 2004 11:40 am

Hi Andrea,

Could you also clarify how your process runs in order to invoke and control the editing, please.

In your first post you mention the following :
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.


For example;
What start method and when and how is it invoked ?
Are you using 'formInDialog' or similar to control editing or some other method ?

It is difficult to assess what you mean by 'close the form' and how this option comes about for the user.



Cheers
Harry
Harry Catharell
 
Posts: 812
Joined: Fri Sep 26, 2003 10:23 am
Location: Milton Keynes, England

Postby a.mariottini » Wed Sep 22, 2004 12:09 pm

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:
1) 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
2) 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 never used "formInDialog" by now.)
Andrea Mariottini
a.mariottini
 
Posts: 120
Joined: Mon Aug 30, 2004 9:20 am
Location: Macerata, Italy

Postby automazione » Wed Sep 22, 2004 1:05 pm

Hi Andrea,

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)
Enrico Arata
Servoy Italia
automazione
 
Posts: 366
Joined: Thu Apr 24, 2003 11:37 am
Location: Torino, Italy

Postby a.mariottini » Wed Sep 22, 2004 2:48 pm

Ok, I'll try with transactions....
Andrea Mariottini
a.mariottini
 
Posts: 120
Joined: Mon Aug 30, 2004 9:20 am
Location: Macerata, Italy

Postby Harry Catharell » Wed Sep 22, 2004 2:56 pm

Hi Andrea,

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 !

Cheers
Harry
Harry Catharell
 
Posts: 812
Joined: Fri Sep 26, 2003 10:23 am
Location: Milton Keynes, England


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 28 guests

cron