0
At Smartgwt, I’m trying to make a MaxLength
in a TextItem
. This TextItem
is in an editable field of a Grid
. Below follows the code used.
How to do a validation on OnKeyPress
which, when it reaches the established limit, does not allow the user to enter any more characters?
final TextItem editorType = new TextItem();
editorType.setLength(100);
editorType.setEnforceLength(true);
editorType.setValidateOnChange(true);
editorType.addKeyPressHandler(new KeyPressHandler() {
@Override
public void onKeyPress(KeyPressEvent event) {
if(editorType.getValue().toString().length() > 100)
event.cancel();
}
});
Please try to make descriptive titles in Portuguese. If you think you have a better one, feel free to [Dit] the question.
– brasofilo
@Brasofilo well observed, had accustomed to the stack in English. Thank you!
– Romero Dias