Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Searchfield with history
What I am trying to achieve is a simple search field with a history of the last typed search queries. After some search I thought the ComboBox component would be nice as it already filters the history when the user is writing his query. Another approach would be a simple TextField and the PopupExtension. But I tried to use this extension some time ago and it had some strange behaviour, so in the end we decided not to use it anymore.
So my problem with the ComboBox is the following: When the user types a new query and the component looses focus - especially when he clicks on the search button next to the combobox - the text input disappears. I can't find any way to change this stupid behaviour and there is no TextChangeListener to store the input nor a method the get the String.
Is there any way I don't see? Or does anybody has an idea how to achieve my goal in another way?
Thanks in advance
Do you have Combobox.setNewValuesAllowed set to true?
Yes of course, the problem is that the user has to explicitly set the new value for example with enter key. If he wrote something and simply clicks outside the field his input is lost...
Okay in that case: Is your combobox set to immediate?
If yes and it still happens try adding a ValueChangeListener which should be fired when clicking outside the field.
If you are able to get the new value in there and there isn't any weird behaviour causing it to be cleared beforehand you can just add the item manually.
If everything fails this behaviour might not be doable in plain Vaadin but you could have a look at Component extension which might solve your problem with a Dom handler that triggers a Button Enter click on the field if on focus lost (using GWT or JS).
This is the behavior of Vaadin ComboBox by design. The only way I see to tackle it is to do some client-side hacking. Write an extension (for text change listener or blur behavior override), or if it fails directly modify the ComboBox client-side code (you'd need to override VFilterSelect.onBlur).