Ask Your Question
0

How to add a "save" and "clear" button to forms?

asked 2015-02-04 05:29:11 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

For arguments sake I work in a "real estate" office. I want to create a database of several buildings, with records of all the residents in each building and all the contractors that work on each building. I would like to create simple forms where new residents or contractors can be add.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2015-02-07 13:53:13 +0200

doug gravatar image

updated 2015-11-11 02:48:45 +0200

Native UI: These functions, save and clear are available in the form navigator at the bottom of the form. This can be made visible or invisible in the properties dialog box of the form control, Data Navigation bar. The icons on Linux look like a blue old-style floppy disk with a sideways triangle (save record) and a looping yellow arrow (undo data entry). Iterating to a new record also will automatically save data, and if the record is closed without saving the user will be prompted to save. image description

Custom controls: If a custom control is desired, it is not a trivial matter to get it to work properly because of the way that LO forms are updated. Updates are multi-step processes, with communication from controls to the form, flags and listeners. To start:

root_doc = ThisComponent
form_container = root_doc.DrawPage.Forms
main_form = form_container.getByIndex(0)

To update, iterate through all the controls on the form and commit changes, update the row; this will return an error if an object in the form does not have the commit method -- tested ok with button and text boxes:

i = 0
Do 
  field = main_form.getByIndex(i)
  field.commit()
  i = i + 1
Loop until i = (main_form.count - 1)

main_form.updateRow()

Or alternately to clear changes, cancel, reload, and go back to original record:

row_num = main_form.getRow()
main_form.cancelRowUpdates()
main_form.reload()
main_form.absolute(row_num)
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-02-04 05:29:11 +0200

Seen: 3,241 times

Last updated: Nov 11 '15