Textfield addValueChangeListener

Hello,

I migrated an app from 1.5 to 2.0.
I have several textfields created dynamicaly like this:

TypedTextField textField = uiComponents.create(TypedTextField.class);

I also added a ValueChangeListener like this:

            textField.addValueChangeListener(textChangeEvent -> {
                try {
                    calculate();
                } catch (NoSuchMethodException e) {
                    throw new RuntimeException(e);
                } catch (InvocationTargetException e) {
                    throw new RuntimeException(e);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException(e);
                }
            });

When i tried to debug the code i saw that in the listener i do not see the changed value from textfield.
On value change i recalculate the sum of textfields
I attached a sample project

bugy.zip (176.7 KB)

chrome_Zu1S4kPBD4

Thank you!

Hi!

You should use addTypedValueChangeListener instead of addValueChangeListener.
It’s written in the documentation.

There is UI Sample: https://demo.jmix.io/ui-samples/sample/text-field-value-change

Regards,
Dmitriy

1 Like