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

Value with type money is 0 instead of empty string #173

Closed
mmarkelov opened this issue Jul 17, 2019 · 1 comment
Closed

Value with type money is 0 instead of empty string #173

mmarkelov opened this issue Jul 17, 2019 · 1 comment
Labels
Working on I'm working on this issue.

Comments

@mmarkelov
Copy link

I got issue when pass falsy value to TextInput with money type:

<TextInputMask
           type="money"
           options={{
             precision: 0,
             separator: ' ',
             delimiter: ' ',
             unit: '',
             suffixUnit: '',
           }}
           value={null}
           placeholder="Test"
           onChangeText={() => {}}
         />

So here instead of placeholder I got 0.
Here is sand

I dive deep into code:

https://github.com/benhurott/react-native-masked-text/blob/0b04ce41087b5e97c5f13f114bdb513c6e107eb3/lib/masks/money.mask.js#L29

We will get 0 when we will pass empty string

So I think it should be some check for empty string before pass value to mask, maybe here:
https://github.com/benhurott/react-native-masked-text/blob/0b04ce41087b5e97c5f13f114bdb513c6e107eb3/lib/base-text-component.js#L76-L80

Something like this:

_getMaskedValue(value) {
       if (this._getDefaultValue(value) === '') {
           return ''
       }
        return this._maskHandler.getValue(
            this._getDefaultValue(value),
            this._getOptions());
    }

I can make PR, if it is right place to do this kind of check

@bhrott bhrott added the Working on I'm working on this issue. label Jul 21, 2019
@bhrott bhrott closed this as completed in 8e31ff3 Jul 21, 2019
@mmarkelov
Copy link
Author

@benhurott thanks for quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working on I'm working on this issue.
Projects
None yet
Development

No branches or pull requests

2 participants