I have following code that needs something smart to deal with typed in chars and detection:
private final MultiWordSuggestOracle mySuggestions = new MultiWordSuggestOracle();
private final Set<String> mySuggestionsData = new HashSet<String>();
@UiHandler("suggestBox")
public void onKeyPress(KeyDownEvent event) {
if (Character.isLetterOrDigit(event.getCharCode())) {
char[] text = suggestBox.getText().trim().toCharArray();
if (text.length != 1) return;
for (char ch : text) {
if (!Character.isLetterOrDigit(ch)) {
return;
}
}
//load data from server into mySuggestionsData
}
}
The question has 3 parts:
How do you test pressed key against alphanumeric chars. Keep in mind this is GWT so I would rather not use regex ( but if there is no other option ...).
What is the best way to detect the length of text typed into the SuggestBox?
Is KeyDownEven the best choise? And why is it triggered twice when any key is pressed?