TextField input only digits

Hi all,

Is there a way to use TextField for inputting only digits? I would like to avoid using validation and showing the error message. The user will not be able to type in other characters other than digits.

Thanks,
Samy

Hello!

You can use the following ways:

  1. Extend TextFieldImpl. Setup EAGER ValueChangeMode, check non-digits symbols and revert previous value.
  2. Include Vaadin add-on to the project (implementation and widget configs): NumberField (Vaadin 8) | Vaadin. Also, you should add widgetCompile task.

I’ve prepared demo project that includes above ways: numberfield-app.zip (84.4 KB)

1 Like