Search code examples
vaadinvaadin7

Vaadin How to SelectAll() in ComboBox field?


Vaadin 7.6.2

What's the best approach to performing a selectAll() in ComboBox field?


Solution

  • If you mean selecting all text in the input field of a ComboBox, there is no a build-in support for that.

    The most elegant solution would be to create your own Vaadin extension, which would provide server-side API for selecting text in a ComboBox.

    The easiest but a bit hackish solution is to defined a unique id for your ComboBox:

    comboBox.setId("my-combobox");
    

    and use the JavaScript API of Vaadin to execute a JavaScript snippet that selects text on client side:

    JavaScript.eval("setTimeout(function() { document.getElementById('my-combobox').firstChild.select(); }, 0);");
    

    I tested this quickly, and it seemed to work in Chrome, Safari and Firefox at least.