How to use TextField with inputFilter

Hello everybody,
I’m using a nifty TextField for Inputs from the user and I want to make sure that only digits can be entered in this textfield. On Github i found a class “FilterAcceptDigits” FilterAcceptDigits but i don’t know how to use this with my Textfield. Are there any examples how to use this?

First I tried to solve the problem with an construction like this

    public void onTextfieldChange(final String id,final TextFieldChangedEvent event) {
    // the boolean ignoreChange is used to prevent having an endless loop of 
    // reading and writing  the textField
        if (!ignoreChange && (event.getText().length()<6)) { // no longer numers needed
            String txt = event.getText();
            int zahl = str2int(txt); // deletes everything that is not in {0123456789} and Returns an integer 
            ignoreChange = true; // to prevent endless loop 
            changeTextfield("txtWertA", String.valueOf(zahl));
        } else {
            ignoreChange = false; // to prevent endless loop

but this behaves strange sometimes. Is there any attribute of a TextField that prevents a changeEvent to be fired when i change the Text by using


I assume the textField variable you have is TextField. So just:

textField.enableInputFilter(new FilterAcceptDigits());

You can do this on the onBind for example. I haven’t tried this myself but seems that it would go like this.