Hello, I am developing a fully responsive web application and I encountered a problem related to the keydown
and keyup
events. Basically, I have these two blocks of code that handle the typing event in a search field:
@Subscribe("searchField")
public void onSearchFieldKeyUp(final KeyUpEvent event) {
if (!searchTextStatic.trim().isEmpty()) {
List<ArticoliClassificazioni> suggestions = getDataService.geArticoliClassificazioni(listino, searchTextStatic);
updateSuggestionsBox(suggestions);
} else {
suggestionsBox.addClassName("hidden");
}
}
@Subscribe("searchField")
public void onSearchFieldKeyDown(final KeyDownEvent event) {
String key = event.getKey().getKeys().toString().replace("[", "").replace("]", "");
if (!key.equalsIgnoreCase("Backspace")) {
searchTextStatic = searchTextStatic + key;
} else {
if (searchTextStatic.length() > 0) {
searchTextStatic = searchTextStatic.substring(0, searchTextStatic.length() - 1);
} else {
searchTextStatic = "";
}
}
if (searchTextStatic.equalsIgnoreCase("")) {
suggestionsBox.addClassName("hidden");
}
}
While everything works fine on desktop, when I tested it on my smartphone, I realized that even though the keyup
and keydown
events are being triggered, they fail to capture the value of the key pressed on the smartphone’s keyboard. How can I fix this? Thanks in advance.
Catalano Paolo