I have spent the past month or so implementing a new Glom feature. It took much longer than expected, involving several large code refactors, and this feature was itself shown to be necessary by previously implementing another difficult feature. But I kept going because the feature seems genuinely and generically useful, if only to a few people. And I knew I was improving that code, reducing code duplication and simplifying it by making code generic and separate.
Anyway, the feature: Glom can show a drop-down (combo box) of choices when the user should enter a field value. This can be a hard-coded list, like “Mr, Mrs, Ms”, or it can be a list of values from a related record. For instance, it can be a list of person names from a contacts field, so you can choose a contact ID. Previously it could only show a value from the immediately-related table.
But you can now do more, because choices now uses the same item layout system as the regular list layout. So, for instance, if you are choosing an Actor’s Agent’s ID, as in this screenshot, you show not only the Agent’s name (as before) -Â You can also show the Agent’s company name (Actors->Agents->Companies), from the doubly-related table. And you can even show the Company’s CEO’s name (Actors->Agents->Companies->CEO) from the triply-related table, if you need that for some non-contrived example. (In this example, I’m ignoring the fact that Actors and Agents and CEOs are in the same Contacts table, though reached via different relationships.)
This is without the Glom user writing any SQL, or having to understand the ugly SQL that’s necessary to do all that. I think that’s nice.
Also, because this uses the regular Glom layout system, you can now specify additional item formatting, such as different font styles (bold in this example), colors, or numeric formatting (such as numbers of decimal points or currencies). You’ll probably be happy with the default formatting that you’ve chosen for those fields though.
While implementing this feature, I also found that GtkComboBox needs:
- To allow the menu to be wider than the GtkCombobox. For the screenshot, I’m using Tristan’s patch for that.
- To allow “columns” to be aligned vertically. This isn’t really possible in GtkComboBox now because you can only add GtkCellRenderers to a single column instead of having multiple GtkTreeViewColumns as in a GtkTreeView. Tristan might make that possible, though it requires some other work first.
One thought on “Glom: Choice drop-downs can show related fields”
Comments are closed.