Search code examples
drop-down-menuvaadinpopupmenuvaadin8

Disallow selecting the empty element of a pop-up menu (a.k.a. drop-down list) such as NativeSelect in Vaadin 8


The pop-up menu widget NativeSelect in Vaadin 8 displays a list of the possible items along with an empty slot at top, presumably to indicate “no item yet chosen”.

enter image description here

How can I disable that empty slot, forbid empty selection?

In preparing the layout, I will set one of the items as chosen by default. The user then is required to always choose one. I want to forbid the no-item-selected case.


Solution

  • To remove that empty item from the dropdown, call NativeSelect::setEmptySelectionAllowed:

    nativeSelect.setEmptySelectionAllowed(false);