-
Notifications
You must be signed in to change notification settings - Fork 419
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
Add allowedDecimalSeparators
prop
#345
Add allowedDecimalSeparators
prop
#345
Conversation
When defined, this prop defines which keys to accept as decimal separators. This is useful in cases where users might want to enter both comma and dot as separators Related issues: s-yadav#324, s-yadav#133, s-yadav#223, s-yadav#261
src/number_format.js
Outdated
/** Check if only . is added in the numeric format and replace it with decimal separator */ | ||
if (!format && decimalSeparator !== '.' && start === end && value[selectionStart] === '.') { | ||
/** Check for any allowed decimal separator is added in the numeric format and replace it with decimal separator */ | ||
if (!format && start === end && allowedDecimalSeparators.includes(value[selectionStart])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: This might not work in all browsers. Should I extract a util instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use .indexOf instead.
Hi @s-yadav, mind taking a look? Happy to iterate on this as/if needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @macobo for putting this. The PR looks good with this two small changes.
src/number_format.js
Outdated
/** Check if only . is added in the numeric format and replace it with decimal separator */ | ||
if (!format && decimalSeparator !== '.' && start === end && value[selectionStart] === '.') { | ||
/** Check for any allowed decimal separator is added in the numeric format and replace it with decimal separator */ | ||
if (!format && start === end && allowedDecimalSeparators.includes(value[selectionStart])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use .indexOf instead.
src/number_format.js
Outdated
|
||
if (thousandSeparator === true) { | ||
thousandSeparator = ',' | ||
} | ||
if (!allowedDecimalSeparators) { | ||
allowedDecimalSeparators = [decimalSeparator] | ||
if (decimalSeparator !== '.') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this if condition. You can just define
allowedDecimalSeparators = ['.', decimalSeparator]
It's okay if dot gets duplicate as we are using this array just for checking includes.
Thanks for the feedback @s-yadav. I've updated the PR. |
Can you also update the readme for the new prop |
Also done @s-yadav. |
I see that you have updated the example file, we will need it to update on README file. |
Oops - sorry, tried to push to the wrong remote thus the PR didn't get updated. Done. |
Merged. Right now I am traveling. Will test it out and release it on npm tomorrow. |
Thank you!
…On Sun, Sep 29, 2019 at 2:14 PM Sudhanshu Yadav ***@***.***> wrote:
Merged. Right now I am traveling. Will test it out and release it on npm
tomorrow.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#345?email_source=notifications&email_token=AABEKVC24R2GFICAALHLBHTQMCEYRA5CNFSM4IZ5WP7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD73REAA#issuecomment-536285696>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABEKVCKCFG4BU5GUCPMTNDQMCEYRANCNFSM4IZ5WP7A>
.
|
Thank you!
|
Hi @tenkij it's worth creating a new issue for these rather than on a merged PR. The pasting issue seems to exist before this PR at least. |
@tenkij the allowedDecimalSeparators is to only allow user to type a character which will be converted to passed decimalSeparator prop. When you paste or change a state value, the incorrect characters are removed. |
But there seem to be some inconsistencies on paste, which I will look into. |
@macobo, ok.
paste '11.11' - ok. |
When defined, this prop defines which keys to accept as decimal
separators. This is useful in cases where users might want to enter both
comma and dot as separators
Related issues: #324, #133, #223, #261