Read-only combo with key listener

  1. I want to present the user a list of all java locales to pick one.
    I dont want any custom inputs, so the txt field should not be editable. Found nothing in the docs for this, but this does the trick:

    public static void makeComboReadOnly(ComboBox<?> combo) {
    // Hacky workaround to force combo opening upwards
    combo.addAttachListener(e →
    combo.getElement().executeJs(
    “try {” +
    " $0.firstChild.setAttribute(‘readonly’, true);" +
    “} catch (err) {” +
    “}”, combo.getElement()
    )
    );
    }

Is there a cleaner way for this?

  1. The list is long and it woul be good, if the user could just type a letter and the popup moves the selection to the first label starting with that letter (e.g. typing ‘g’ should move to ‘German (Germany)’) Is this possible at all with the Vaadin combo?
  1. Combo box is the right way. Another solution could be to use Select. I would argue your hack isn’t needed, as only the values present in the list are by default available on the server side, it’s only used to filter (your second point)

  2. yes that’s also possible with the Combo box, you can configure how the search should work, like using startsWith or contains

thanks, Select is exactly working as expected