Use the "Value Relation" field widget to select multiple items from a list
1. Create a spreadsheet with two columns.
Call the first column "key." In this column, enter the values that you want saved in the attribute table. You can use your keywords, or you can assign a shorter key to each keyword. For example, I used numbers as my keys. The value "hotel" will be saved in the attribute table as 1. This allows you to store relatively long values in a more compact format. You could also use abbreviations, such as h for hotel, and g for garden. If you prefer, you can put the same value in each column.
Call the second column "value." In this column, put all of your keywords ("restaurant", "hotel", "garden" and so on).
[![enter image description here][1]][1]
Save the spreadsheet in csv format.
2. Import the csv as an attribute-only table (ie without geometry).
3. Set up value relation widget
Open layer properties for the historical areas layer.
Open the Attributes Form tab.
Select the field (in my example the field is "categories").
For Widget Type, choose "value relation." For layer, select the table you added in step 2. (in my example the table is called "book2"). For key, select the key column. For value, select the value column.
When you create a new point, the data entry form will now give you a checklist.
The attribute table will store multiple values in a single field:
Best Answer
Use this expression, where
name
is the name of the input attribute field:If you also want to avoid any whitspaces (space etc.) at the beginning or end of the text field, e.g. resulting from deleting a bracket at the beginning (like your 3rd example), add a
trim()
function: