Ask Your Question
1

How to get focus on a subform in LibreOffice Base using tab?

asked 2019-04-14 22:07:50 +0200

arjan gravatar image

updated 2019-04-14 22:19:13 +0200

There's a question and answer (LibreOffice Base; Tab order from mainform to subform) on SO which almost solve the question I have, but not completely.

I have a table mytable (id, name, textfield). I'm displaying id and name in a form with a table layout (table control). I've added the column textfield from the same table as a subform with a text box control (the reason is that I want to enter text with newlines, while being able to navigate the records quickly in the main table). Here's what it looks like in design view:

Form and subform from one table

I've added this Basic macro, based on the two answers linked above:

Sub Main

Dim root_doc As Object
Dim form_container, form_ctrlr As Object
Dim main_frm, sub_frm, tab_target As Object
root_doc = ThisComponent
form_container = root_doc.Drawpage.Forms
form_ctrlr = root_doc.getCurrentController()
main_frm = form_container.getByName("MainForm")
sub_frm = main_frm.getByName("SubForm")
tab_target = sub_frm.getByName("TextField")
form_ctrlr.getControl(tab_target).setFocus()

End Sub

Now, if I add the macro on the event When losing focus of the name column, I do get focus on the textbox when pressing Tab, but on the next row instead of the current record.

If I add the macro to the event On key press of the name column, I get what I want when pressing e.g. Space, but Tab or Enter only take me to the next row in the main form.

Is there a way to get focus on the subform at the current record by pressing Tab?

edit retag flag offensive close merge delete

Comments

Jim K gravatar imageJim K ( 2019-04-15 15:08:40 +0200 )edit

2 Answers

Sort by » oldest newest most voted
1

answered 2019-04-15 03:26:59 +0200

Ratslinger gravatar image

Hello,

It appears the problem you are having is because your primary form contains the table control and the sub form has just the text field - just the opposite of your link.

Now in using the table control on the primary form, certain actions will occur with different key strokes such as using the Tab or Enter keys. These will take you to another field within the control, another record within the control or to another control depending upon where in the control you are and which key you are using. So all being said, the table control was not designed to do what you are attempting to do, at least not easily.

So it is easy enough to have your form and simply, when you have selected the proper record in the table control, mouse click the text field to give it control. However with you comment on ...being able to navigate the records quickly... it appears you want to get there with a key entry.

To override the internal Tab, Enter or other possible key functions can be problematic and it would be easier to use a key combination such as Ctrl & Tab to change focus to the text field.

First change your form. No sub form needed. Move the TextField over to MainForm. You can delete the sub form. Remove any existing Event links to macros you may have - not needed.

You will need this macro:

Sub Main
    Dim oForm, oCtrlr, oField As Object
    oForm = ThisComponent.Drawpage.Forms.getByName("MainForm")
    oCtrlr = ThisComponent.getCurrentController()
    oField = main_frm.getByName("TextField")
    oCtrlr.getControl(oField).setFocus()
End Sub

The names remain the same as before so no changes needed there. Now attach this to a custom key combination as mentioned - from menu Tools->Customize. Set up on Keyboard tab.

Once set you will be able to change focus from a table control field to the text field and from the text field back to the table control with the Tab key.

edit flag offensive delete link more

Comments

I'm puzzled by this answer. The field/form switching behavior of Ctrl + Tab is the default, is it not? Tested on LO 6.1.0.3 on Windows. It works whether a subform is used or not. So there seems to be no need for a macro.

Jim K gravatar imageJim K ( 2019-04-15 15:30:54 +0200 )edit
1

Thanks for looking into this. Somehow I can't get it to work. I've assigned the macro to Ctrl + Space, but it selects the current row in the table. I've also tried changing the line oField = main_frm.getByName("TextField") to use oForm instead of main_frm which I suppose it should read.

arjan gravatar imagearjan ( 2019-04-15 15:59:59 +0200 )edit

Huh, I didn't know that Jim, but you're right Ctrl + Tab already works. I'd still like to get the macro to work, because Shift + Space or Ctrl + Space (option to use left Ctrl) are more ergonomic.

arjan gravatar imagearjan ( 2019-04-15 16:04:12 +0200 )edit

@Jim K is correct. Actually forgot that combination was there.

Ratslinger gravatar imageRatslinger ( 2019-04-15 16:39:32 +0200 )edit

Apparently, the combinations Shift + Space (inserts a space) and Ctrl + Space (selects entire row) will not work as custom hotkeys in a table. Some combinations work, for example Ctrl + F5.

Jim K gravatar imageJim K ( 2019-04-16 15:41:23 +0200 )edit
1

Allright I found a decent key combo (Shift + Enter) that works. Thanks both!

arjan gravatar imagearjan ( 2019-04-17 00:42:53 +0200 )edit
1

answered 2019-04-15 15:27:02 +0200

Jim K gravatar image

updated 2019-04-15 15:36:23 +0200

The simple solution is to remove the macro and press Ctrl + Tab to go to the subform. To return to the main form, press Tab.

The behavior of Tab to go to the next record cannot be disabled, as far as I can tell. (I tried returning False from an event handler but it did not stop the event). To work around this problem, it would be necessary to go to the previous record with a macro, in order to end up on the same record.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-04-14 22:07:50 +0200

Seen: 54 times

Last updated: Apr 15