1

Is there a way to open the dropdown of a combo box programmatically?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Lahiru Chandima
  • 22,324
  • 22
  • 103
  • 179
  • last time i checked, that was not triggerable from server. see also http://stackoverflow.com/questions/23672032/how-to-open-a-vaadin-combobox-programmatically and http://stackoverflow.com/questions/25565527/how-to-open-a-vaadin-combobox-by-code for inspirations. depending on your usecase, there are plugins addressing popular behaviours (e.g. https://vaadin.com/directory#!addon/searchfield) – cfrick Jul 20 '15 at 06:59

3 Answers3

1

As @cfrick said, triggering the event from server side is not possible, but it is possible from the client side.

To run javascript code, you can use

Javascript.getCurrent().execute(myCode);

Notice that this code will only run after all the serverside operations are performed, and after the vaadin engine renders the response.

The code to be passed to javascript must be similar to this:

var event;
event = document.createEvent('MouseEvents');
event.initMouseEvent('mousedown', true, true, window);
$("select").dispatchEvent(event)

To ensure a good behaviour you should call setId() in your dropdown and use that value as jquery selector.

References:

https://vaadin.com/book/vaadin7/-/page/advanced.javascript.html - How to run javascript from vaadin Can I open a dropdownlist using jQuery - client side solution http://demo.vaadin.com/sampler/#ui/data-input/multiple-value/drop-down-menu -the javascript code works in the sampler

Community
  • 1
  • 1
Nuno Pinheiro
  • 320
  • 2
  • 8
1

if I'm not mistaken, you can use the following method of your combobox as of Vaadin 14.6.6 (flow):

.setOpened(true)

I'm currently using Vaadin 20 (flow) and I'm showing a combobox which is triggered by another button's clickListener. By using this method, my selectionItems immediately show.

Paul
  • 841
  • 13
  • 20
0

This feature ( openPopup() and openPopup(int page) methods ) is included in PrefixComboBox add-on for Vaadin 8, which an extended ComboBox, a collection of missing features.

Tatu Lund
  • 9,949
  • 1
  • 12
  • 26