RE: Combobox

Do you need to have text input enabled in the ComboBox at all? You can disable it by using setTextInputEnabled(false).

-Olli

Hi everyone,

I’ve got a weird behaviour and I don’t know how to avoid this.
I’ve got a form with a combobox and I’ve got a button with shortcut key.
If I call the button action when the combobox has the focus then the content of the combobox is filtered.
The user has to click on the combobox arrow (“v”) or clear the combobox.

Here an example of my problem.
Steps to reproduce: select “first” in the combobox, tap F12
The behaviour is different is the user click on the button.

@Theme("mytheme")
public class MyUI extends UI {


@Override
protected void init(VaadinRequest vaadinRequest) {
final Binder<Person> binder = new Binder<>(Person.class);
Person p = new Person();
VerticalLayout layout = new VerticalLayout();
TextField name = new TextField("Name");
ComboBox<String> rank = new ComboBox<>("combo");
rank.setItems("first","second","third");

Button saveButton = new Button("Save", e -> {
Notification.show("save OK", Notification.Type.HUMANIZED_MESSAGE);
});
saveButton.setClickShortcut(ShortcutAction.KeyCode.F12);
binder.forField(rank).bind(Person::getRank, Person::setRank);
binder.forField(name).asRequired("Required").bind(Person::getName, Person::setName);
binder.readBean(new Person());
layout.addComponents(name,rank,saveButton);
setContent(layout);
}

public class Person {
private String name;
private String rank;
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getRank() {
return rank;
}

public void setRank(String rank) {
this.rank = rank;
}
}

@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {

}


}

Is there any workaround ?

Thanks,

I don’t need to add new item in the combobox but I need to filter inside the combobox.

With setTextInputEnabled(false), you cannot use keyboard (nativeSelect is better in this case).

EDIT: Thanks for your answer :). For simple combobox, it’s a good workaround but my 3-items combo is just an example. I really need this filter.

Ah, it’s a known issue, then. There’s even a sample project to reproduce the issue included in the GitHub ticket.

-Olli

There is a opened bug for that https://github.com/vaadin/framework/issues/8684
In fact, my problem is not related to the shortcut key on the button.

When I use key like F12 (or CTRL-A or “Left”) then the combobox filters all elements except the selected item.

You can see the difference between Vaadin framework combobox and vaadin elements combobox.
Choose a country (or Helium element :stuck_out_tongue: ), type “Left” on your keyboard.
https://demo.vaadin.com/sampler/#ui/data-input/multiple-value/combo-box
https://vaadin.com/elements/-/element/vaadin-combo-box#demos