question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[onChange] value not change when i delete negative symbol on textbox with backspace

See original GitHub issue

version 4.0.8

When typing the following: '1 then ‘2’ then ‘-’, or ‘-’ then ‘1’ then ‘2’ It would display as ‘-12’.

but when i delete negative symbol with backspace, that value cannot be change and still -12 not 12

im using onChange props

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

4reactions
mklosterboercommented, Oct 21, 2020

As a workaround, I decided to use onValueChange() only if the user is removing the negative from a number. Here is a sandbox with this working or see below for the code snippet inside our formatter wrapper.

const handleOnChange = (e) => {
    var floatValue = getFloatFromFormattedNumberString(e.target.value);
    onValueChange(floatValue ?? null);
};

const handleOnValueChange = ({ floatValue }) => {
    // value was previously negative, and the user is removing the negative
    if (value.toString().charAt(0) === "-" && floatValue >= 0) {
        onValueChange(floatValue);
    }
}
1reaction
mackankowskicommented, Oct 16, 2020

Hey all,

Nothing works but this:

const [value, setValue] = useState();
<NumberFormat
            onValueChange={({ value }) => {
              setValue(value)
            }}
            value={ value }
            ....

Any other conclusions? If not, let me try to commit the fix pretty soon…

Best regards, Maciej

Read more comments on GitHub >

github_iconTop Results From Across the Web

On-change not triggered when input cleared - OutSystems
Hi there,. I have an input box which is linked to an autocomplete widget. When the input box is blank, I show a...
Read more >
html - Is there any way to prevent input type="number" getting ...
I can still copy paste negative values into the input field. I will look for another solution. This one doesn't work completely for...
Read more >
Prevent unwanted characters in <input> | by MelkorNemesis
Say you want to delete some characters from the <input> . You press Backspace and get event.key equal to Backspace . And because...
Read more >
Regular expression to allow only numbers and comma
11:52 PM mobile number validation accept numeric , Number , react allow only numbers in textbox , Regex Edit Use value and onChange...
Read more >
Editing cells - TreeGrid
Cell editability. upd 13.0 <Cfg> int. Editing. [1]. If and how values of grid can be edited. It does not affect rows ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found