How to check if form variables have changed

Questions and answers for designing and implementing forms in Servoy

How to check if form variables have changed

Postby Bernd.N » Mon Aug 28, 2017 2:31 pm

With databaseManager.getEditedRecords() I can check if the record of a form has changed.
But when all field-dataproviders of a form are bound to form variables instead of fields of a record, how can I check if any of those have changed?

The case is that I need to fire a specific action only when something on that form changed.

I could create one simple onDataChanged-Method that will set a switch to "changed!" when one field was changed, and hook that method to all fields.
But is there maybe a more simple method?
Bernd Korthaus
Servoy 7.4.9 SC postgreSQL 9.4.11 Windows 10 Pro
User avatar
Posts: 543
Joined: Mon Oct 21, 2013 5:57 pm
Location: Langenhorn, North Friesland, Germany

Re: How to check if form variables have changed

Postby steve1376656734 » Tue Aug 29, 2017 10:49 am

You could try using an in-memory datasource and then you could do normal data-binding and use the databaseManager.getEditedRecords()
Posts: 248
Joined: Fri Aug 16, 2013 2:38 pm
Location: Lanzarote

Re: How to check if form variables have changed

Postby paronne » Tue Aug 29, 2017 11:40 am

Hi Bernd,

Just for your information, if you are using Servoy 8.1+ forms have an event onElementDataChange() which is fired each time a dataprovider changes value in the form. It overcomes the problem of having to bind the onDataChange to each single element of the form for generic logic.
Still you have to store somewhere the state of the variable to "changed" and it won't directy tell you if the dataprovider is bound to a form variable or to something else (scope variable/ foundset dataprovider); eventually you can figure it out yourself from the JSEvent of the onElementDataChange, which gives you the elementName and the dataSourceID (event.getSource().getDataSourceID()).

Posts: 174
Joined: Fri Nov 02, 2012 3:21 pm

Return to Forms

Who is online

Users browsing this forum: No registered users and 2 guests