-
-
Notifications
You must be signed in to change notification settings - Fork 21
Description
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.
simple-mask-money/src/set-mask.ts
Line 215 in f2de36e
| 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
Metadata
Metadata
Assignees
Labels
Projects
Status