Base: replicate subform for each related element


I currently have a schema with 3 tables:

+-----------+           +-------------+             +-----------+
| documents |           | groups      |             | positions |
+-----------+           +-------------+             +-----------+
| id        | <---+     | id          | <----+      | id        |
| name      |     |     | name        |      |      | name      |
+-----------+     +-----+ document_id |      +------+ group_id  |
                        +-------------+             +-----------+

Now I want to create a form for documents.

it should look a bit like this:

Nameinput: <input>

groupname1: <input>
table of positions

groupname2: <input>
table of positions

emptygroupname: <input>
empty table of positions

The empty group + table as last entry is to add a new group to the document.
If I add a new element, a new empty input + table should appear to add another one and so on.

Now I know I can use a tablecontrol for the positions and that would be fine, but how would I do it with the Groups?



Creating this form is simply the use of internal forms and sub forms. The main form is ‘Documents’ with a sub form to that of ‘Groups’ and then a sub sub form to that of ‘Positions’. You final section of “emptygroupname” is not necessary because you can add new groups in the ‘Groups’ sub form any time.

Which controls you use is not a concern. Each can be comprised of individual controls or by using table controls (as used in the sample attached). The connection of Form->SubForm->SubSubForm is done through the internal form properties via the Link master fields and Link slave fields properties on the Data tab.

More information on Forms can be found in the LO documentation → LibreOffice Base Handbook. See Chapter 4 - Forms.

Sample ----- Groups.odb

In this sample the is only one form. On that form when you select a Document it displays the Groups for that Document in the middle table control. When a particular Group is selected from a Document it displays, in the bottom table control, the Positions within the selected Group.

I think you did not understand my problem correctly.

I always want to see all positions and all groups in a form.

I know I can just use subgroups and then tablecontrols for all forms. but that does not give me the behaviour I want.

See here for a mockup:

If I understand you correctly, you are wanting to see ALL groups and ALL positions for any Document on a Form. Since this a varying amount of information from Document to Document, it would certainly require doing this through macros. The form would actually need creation at runtime since it is unknown what needs to be displayed until a actual Document is selected. A lot of work!

This would be almost trivial with any good UI framework.

But it seems it is really hard to do in base :frowning:
I worked around it by adding a document_id field to the positions table and have groups and positions side by side. I need to add the group_id manually to the positions now though.

@belst Could you please point me to one where this is trivial? Have worked with many and not seen this type of feature. With just a simple set of tables, this could result in thousands of controls on a single form making it impractical to work with.

in qt, for example I’d create a widget which contains the subform and then instantiate it depending on the results of the query. probably less code than writing a macro to do it in base.

Sure it could create thousands of controls. in my case it would probably be maximum of 5 subforms.

But even then, that is nothing something like pagination or reuse of controls when they scroll out of the visible area (hard) could not fix.

@belst Thank you for the response. Have dealt with QT before and, only my opinion, would hardly use the phrase ‘almost trivial’. Your comment about creating a widget could also be done, in a manner, using Python. You can always go to QT if that is so much easier for you.