parttio / textfieldformatter

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

TextField server-side value does not always match what is displayed #56

Closed johanneshayry closed 1 year ago

johanneshayry commented 2 years ago

At least with custom blocks if you keep writing characters after the maximum number of characters, the latest keypress is appended to the visible value.

Let's say you have a formatter that forces three blocks 'X-XX-XXX'. If you write 123456789 you will get a visible value 1-23-456, but the server-side value is 1-23-4569.

Not a nice workaround is to call setMaxLength for the TextField.

johanneshayry commented 2 years ago

Additionally, when pasting a value, the full value is set to the server-side.

johanneshayry commented 2 years ago

Regression from 073f3eb7b8d13370c008c5ba112cbc3cc17891fb when attaching Cleave.js to the underlying <input> instead of the vaadin-text-field element.

forest19 commented 2 years ago

I've just checked and the same problem is still present in version 5.4.0. thanks for a workaround!

johanneshayry commented 2 years ago

I guess an acceptable kludge would be to set the maxLength through this extension whenever a pattern is set. I have hard time to come up with another solution. If Cleave.js is attached to the vaadin-text-field the value property is correctly set, but the caret jumps around. If Cleave.js is attached to the underlying input element, the caret works, but (of course) the input value changes are not observed by the Vaadin web component.

syampillai commented 1 year ago

Phone number formatting has the same issue. Also, there is o way to set the max length because the allowed length depends on the country of the phone number.