vaadin / flow-components

Java counterpart of Vaadin Web Components
100 stars 66 forks source link

TextField setAllowedCharPattern clipboard strip #6155

Open dpizzagalli opened 5 months ago

dpizzagalli commented 5 months ago

Describe your motivation

During normal data-entry activities, information is often copied from documents and pasted into structured fields. If the string in the clipboard contains non allowed characters, then the entire paste action is prevented, the TextField should instead allow the paste action by skipping the forbidden characters be added to the value, increasing the productivity of data-entry activities.

For example, if there is a TextField that do not allow whitespaces, the user copies " Value ", and paste it inside the TextField. Now no value is added, forcing the user to understand the reason (which might be hard for non-tech users), go back to the original data e only copy "Value".

Describe the solution you'd like

The ideal solution would be to have the TextField automatically skip the non allowed characters, but still considering the valid ones. For example, copying " Value " would only add "Value" to the TextField. This could happen by editing the paste behaviour here

Describe alternatives you've considered

It is possible that the current behaviour would fit better certain use cases, for example when pasting money currency amount, an entry like "12,34" could unexpectetly become "1234". For this reason, it might be wise to contextualise this behaviour with a flag like stripNotAllowedCharacters

Additional context

This proposal arisen to my knowledge after interacting with developers of applications subjected to heavy data entry activities

knoobie commented 5 months ago

Do not use allowed character on the client side and instead add validations and or converters in your binder to either inform the user about illegal character or just remove them yourself.