Tagging - A dropdown with values from a table + option to add or delete

I'm currently using the select2 from the forge and managed to show dropdown values from a table. also it is possible to use the dropdown as an input field and this triggers an action "

SyntaxEditor Code Snippet

OninputMultiSelectedValueChange

where I added some logic to add the new record to the table.

However, the select2 tagging comes with the option for the user to remove tags which I don't know how to catch this part.

Is anyone using this or has a better way to create a dropdown list with values from a table plus the option to add or remove own tags?

Hi.

To handle the add and remove functionality within the same account, you'll need to compare the number of records in the database vs the number of records selected in the select2. 


From the deletion, you have to iterate through the database records that you have and find out which record is was deleted to remove it from the database. 

There are two System actions , ListFilter and ListAny, that can help you with this task. You might need to add them from the dependencies popup.


Gabriel 

Hi Gabriel,

thanks for your fast response! I was about to reply I don't know how to catch the deletion event. But when I understand you correctly any activity in the dropdown should be added/removed in a list and then updated in the db.

Maybe I can just do a delete * where userid=getuserid() and then make an insert of the whole list. This would probably be faster than comparing.


Thank you I will try this idea!

I don't recommend storing the whole list, store just the ones that the user selected, because you can imagine how big your database would be if a lot of users accessed that select2. This will save up some space in the database. It will require more logic, to add or to remove only 1 record, but you'll get a cleaner solution. 

And if you plan to reuse this selection, you can have a calculated attribute in the source aggregate where "IsSelected" would be SelectedRecord.Id <> Nullidentifier() in a left join between the source list and the new table with the selected value.


Good luck


So I made the list and it works, but again I got stuck because the deletion of a tag doesn't seem to trigger anything I could catch :(

I'm trying to solve this all within the dropdown, no additional buttons.

Adding a value is triggering the action, but deleting not.