Implementing maximum width of a TextItem in Smart GWT 2.6

0

In SmartGWT, I'm trying to make a MaxLength into a TextItem . This TextItem is in an editable field of Grid . Below is the code used.

How to do a validation in OnKeyPress that, when it reaches the established limit, does not allow the user to type any extra character?

    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();
        }
    });
    
asked by anonymous 18.01.2016 / 12:11

0 answers