ComboBox with the ability of deleting items


I’m Raul and I’m working with Vaadin 14 for the moment. I need to implement a smart ComboBox. One that can store new values put in by the user and one that can remove those values if the user chooses so. Something like having an “X” next to each item in the combobox.

Do you have any suggestions on how should I approach this? I’m guessing the storing part is easy but how do I remove stuff?

This question is twofold:

  1. You need to have UI to remove the items interactively. There are two techniques in ComboBox, which could be used. You can use either ComponentRenderer or TemplateRenderer to add the X button in the options list.

See more

  1. You need method to remove item from the data source. I.e. you can use X button click listener and when fired you can remove the item from the DataProvider and call dataProvider.refreshAll() to update the option list. If you use ListDataProvider, this is trivial (just get the backing list and remove the item), in other cases it requires to build a bit more custom logic that fits your specific data source.

Thank you.