parttio / textfieldformatter

TextField Formatter Vaadin add-on
Apache License 2.0
13 stars 9 forks source link

How to programmatically set value #60

Open jonasrotilli opened 2 years ago

jonasrotilli commented 2 years ago

I have a text field that uses Numeral. When the user types, everything works perfectly. When I try to programmatically put a value, the formatting is not done. What's the secret for it to correct the formatting after I set a value? Example:

TextField textTest= new TextField("Test");
new NumeralFieldFormatter(".", ",", 3).extend(textTest);

//If I set a value:
textTest.setValue("1234.4");

It's not formatted, it's only if the user modifies anything.

I use in Vaadin 23.

jonasrotilli commented 2 years ago

Nobody knows?

mrgreywater commented 1 year ago

my workaround:

    textField.addValueChangeListener(event -> {
        if (!event.isFromClient()) {
            event.getSource().getElement().executeJs("this.querySelector(\"jh-textfield-formatter\").cleave.onInput(\"" + StringEscapeUtils.escapeJava(event.getValue()) + "\");");
        }
    });