Setting combobox items depending on other combobox value

Hello!

I’m trying to set items to combobox depending on other combobox value, but I’m getting errors and it doesn’t work. If I make a new combobox every time to set items, it works, but then I also have to create a new valuechangelistener under the combobox which I’m getting the value from and that’s not the proper way.

For example:

                    if (combobox1.getValue().equals("1")) {
                        combobox2.setItems(getItemsFromFile("1.txt"));
                    } else if (combobox1.getValue().equals("2")) {
                        combobox2.setItems(getItemsFromFile("2.txt"));
                    }

(TypeError) : Cannot read property ‘reset’ of undefined
(TypeError) : Cannot read property ‘confirm’ of undefined
(TypeError) : Cannot read property ‘set’ of undefined
(TypeError) : Cannot read property ‘updateSize’ of undefined

While this one works:

                    if (combobox1.getValue().equals("1")) {
                        combobox2 = new Combobox<>();
                        combobox2.setItems(getItemsFromFile("1.txt"));
                        
                       combobox2.addValueChangeListener(e-> {
                           
                       });
                        
                    } else if (combobox1.getValue().equals("2")) {
                        combobox2 = new ComboBox<>();
                        combobox2.setItems(getItemsFromFile("2.txt"));
                        
                        combobox2.addValueChangeListener(e-> {
                            
                        });
                    }

How it should be done? Using Vaadin 12.

You might be hitting this bug: https://github.com/vaadin/vaadin-combo-box-flow/issues/169

-Olli

Yep, setItems(“”) fixed it. Thanks for the quick answer!