# Multiple Tags autocompletion field in Base

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 close merge delete

Sort by » oldest newest most voted

more

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.

( 2015-07-11 04:26:37 +0200 )edit

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.

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

more