user1949788
user1949788

Reputation: 1

Write to database only when a button is pressed

I have a form with two datasources that are linked by using an outer join. It is written to the database by using Form Datasource Unit of Work framework.

As of now, the data gets written when moving from one datasource form control to another form datasource control. I want to only activate/write using Form Datasource Unit of Framework when a button is clicked.

Is there a way to prevent automated write function when moving from one Form Control to another?

Upvotes: 0

Views: 1792

Answers (1)

Jan B. Kjeldsen
Jan B. Kjeldsen

Reputation: 18051

First have a look on HowTo: Unit of work implementation for a Form to check you align with that. The official doc is Change Group and Optional Record Modes.

The writes are issued because you are "leaving" a record, see Event Method Sequences when Focus is Removed from a Record.

This is the sequence when validateWrite returns true:

  1. leaveRecord return true
  2. validateWrite return true
  3. writing
  4. written
  5. leaveRecord return true
  6. leaveRecord return true (again)

This is the sequence when validateWrite returns false:

  1. leaveRecord return true
  2. validateWrite return false
  3. leaveRecord return false

So you can override validateWrite to silently return false, when you do not want to save. Be sure to call super() when you do want to save!

Or you can call leaveRecord yourself to force a write:

if (record_ds.leaveRecord(true))
{}

When calling record_ds.leaveRecord(true) please observe that it may not save the record, e.g. if validation fails. In that case leaveRecord will return false.

Observe that you are working "against" the standard working, this will make your form work differently than other forms.

Upvotes: 1

Related Questions