Lahiru Chandima
Lahiru Chandima

Reputation: 24138

Vaadin: Open combo box dropdown programmatically

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

Upvotes: 1

Views: 1536

Answers (3)

Paul
Paul

Reputation: 1170

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.

Upvotes: 1

Tatu Lund
Tatu Lund

Reputation: 10643

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.

Upvotes: 0

Nuno Pinheiro
Nuno Pinheiro

Reputation: 319

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

Upvotes: 1

Related Questions