Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💡 [REQUEST] - Do not change initial empty values to zero #79

Open
vitorccs opened this issue Sep 20, 2024 · 0 comments
Open

💡 [REQUEST] - Do not change initial empty values to zero #79

vitorccs opened this issue Sep 20, 2024 · 0 comments

Comments

@vitorccs
Copy link

Start Date

No response

Implementation PR

No response

Reference Issues

No response

Summary

Do not change/mask initial empty values ("") unless user types the first character

This has been reported originally in another issue (#51), however, it has been 3 years and I guess the old behavior returned.

PS: I believe this may be an usability improvement in some UX scenarios - since the mask will only assist the user to type a value, but never to assume/input an initial value.

Solution

To prevent break change, I suggest to implement a new config parameter or use the existing allowEmpty which is not officially documented in the project.

const initialValue = formatToMask(element.value.split(''), true);

In my local tests, I found out the solution could be simple like below and all tests passes successfully

const initialValue = !allowEmpty || element.value ? formatToMask(element.value.split(''), true) : '';

References:

Other libraries which allow initial empty values
https://plentz.github.io/jquery-maskmoney/
https://github.com/dm4t2/vue-currency-input
https://github.com/jonathanpmartins/v-money3

Basic Example

Must remain empty

<input value="">

Must be masked

<input value="0">
<input value="1234">
<input value="1234.00">

Drawbacks

This improvements depends on a new configuration parameter to prevent creating a break change for existing users which prefers the current behaviour

Unresolved questions

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ToDo
Development

No branches or pull requests

2 participants