Ask Your Question
0

Multiple Tags autocompletion field in Base

asked 2015-07-10 10:31:10 +0200

mokas01 gravatar image

updated 2015-08-24 18:44:00 +0200

Alex Kemp gravatar image

Hi,

I would like to create a tag field in Base. I used a combo box. I have something nice and working (with autocompletion) but, I don't know how to enter multiple tags for one object. If I do so, and whatever the separator I used, its always handled as one new tag : "tag1; tag2" has become a third one, although I don't want to. Have you got an idea on how I could do this ?

Thanks

Component : Base LibreOffice 4.4.3.2 for OSX

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2015-07-11 00:39:14 +0200

frofa gravatar image

updated 2015-07-12 08:33:43 +0200

One way of doing this is to add another 2 tables - TAGS and TAGS_CHOSEN - to your design. The first of these contains one row per tag (and will be used to populate your 'choose a tag' listbox as below) - you might already have this table in your design to populate your 'choose a tag' combo box. Rows in the second TAGS_CHOSEN table are in a 1:n relationship to your primary table records (i.e. one primary record is linked to multiple rows in the TAGS_CHOSEN table via the primary record ID). Your FORM would have a tag list (using a data-grid control) in a subform which gets filtered according to the selected primary record, and each new tag may be added via a drop-down listbox (field-type in the data-grid column) with its tag-list sourced from the TAGS table. You could even have an extra column in your TAGS_CHOSEN table to store a batch number so you could recall previous search-tag/keyword combinations - see HERE.

edit flag offensive delete link more

Comments

the subform/child-table approach is the way. There is a multiselection property for the List box, but it is broken on at least some platforms. The only additional alternative is to use a macro-heavy approach consisting of direct-SQL writes to the table and reloads of a child form, which probably is more trouble than it is worth.

doug gravatar imagedoug ( 2015-07-11 04:26:37 +0200 )edit
0

answered 2015-07-11 17:32:36 +0200

pierre-yves samyn gravatar image

Hi

LibreOffice's database is relational. With such databases, multi-valued fields are indeed managed by related tables. This is why listboxes only allow multi-select if the control is not bound to a database field.

With listbox not bound to a database field, a macro can collect selected items, and assign them to a field. In the following MultiSelect.odb the macro is associated to the click of the button.

screenshot

Here is the code:

Sub MultiSelect(oEvt)

const sep = "|"

dim oForm as object, oListCtrl as object, oCtrl as object
Dim i as integer

oForm = oEvt.source.model.parent
oListCtrl = oForm.getByName("ListBox1")
oCtrl = oForm.getByName("Fruit")

with oListCtrl
    select case ubound(.SelectedValues())
        case -1
            msgbox "no selection", 64, "Multiselect"        
        case 0
            oCtrl.text = .SelectedValues(0)
            oCtrl.commit
        case > 0    
            oCtrl.text = ""
            for i = 0 to  ubound(.SelectedValues()) - 1
                oCtrl.text = oCtrl.text & .SelectedValues(i) & sep
            next i  
            oCtrl.text = oCtrl.text & .SelectedValues(i)
            oCtrl.commit
        case else   
            msgbox "This should not occur...", 64, "Multiselect"        
    end select
end with

end sub

As you can see, the separator | is given at the beginning of the macro. You can replace by what you want...

Finally, as the listbox is not associated with a field, it is not cleared on record changing. The following macro allows for example to reset the list. It is associated with the form event "After changing".

sub ChangeRecord(oEvt)

dim oForm as object, oListCtrl as object

oForm = oEvt.source
oListCtrl = oForm.getByName("ListBox1")
oListCtrl.SelectedValues() = array()

end sub

If this answers the question, thank you to click on the ✔ to mark it ANSWERED.

Regards

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-07-10 10:31:10 +0200

Seen: 1,065 times

Last updated: Jul 12 '15