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.

Allow formatOnBlur

See original GitHub issue

Are you submitting a bug report or a feature request?

Feature Request

What is the current behavior?

Formatting is immediate when user is doing an input. When the user is trying to edit a number with formatting, e.g., 1.5 percent is presented/formatted as 1.5 to user (value is stored as 0.015), the problem is when the user tries to backspace the number 1 (when the cursor is at the position before the dot in 1.5) and replace it with 3, the input becomes .5 (parsed and stored as 0.005), but then the formatting kicks in immediately, the .5 user input is replaced with 0.5, and the cursor goes to the end of the number. Then the user has to press left key two times, and then press 3. This gives a bad user experience since the user can’t edit the text in the most natural way possible.

Another problem is when the user wanted to type 2.5, as soon as 2. is typed, the value is formatted as 2, this won’t give user a chance to type 2.5 in the most natural way. The only way for 2.5 can be typed is by typing 25 first and then pressing the left key and then typing the . character.

What is the expected behavior?

Give an option that formatting happens only when the input loses focus.

Demo for the expected behavior. Backspace the number 1 in the Interest Rate per Annum of 1.5, and then press 3. http://jsfiddle.net/0zw630d4/4/

Sandbox Link

Demo: https://codesandbox.io/s/nk1828jz70

What’s your environment?

Sandbox

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
erikrascommented, Mar 21, 2018

Sounds like you want a formatOnBlur?

2reactions
MichaelBuencommented, Apr 21, 2018

Is that HOC pattern the React middleware? I’ve yet to learn how to create my own middleware in React.

Here’s the desired output: https://codesandbox.io/s/yp1j7pynqz The form needs both raw value (value when the input is the focus?) and formatted value. Formatted value activates when the input is not the focus, raw value activates when the input is the focus. And then there’s the model value, user inputs 1,234 percent as 1234 (not 1,234) just like in Excel, and then receives 12.34 as the model value, and formatted as 1,234. If the user inputs 50, the model value is 0.5, the formatted value is 50.

Important is, formatting of value model should not happen while the user is inputting the value, as the formatted value gets in the way when its value is parsed to model value. Currently, user inputs 2., it’s formatted as 2 immediately, user doesn’t get the chance to input 2.5 as the . gets scrubbed during formatting of parsed value of 0.02 to 2 only, missing the dot. Here’s the not user-friendly format/parse pairing: https://codesandbox.io/s/nk1828jz70

If that can be tackled neatly in middleware, I’ll explore it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Final Form Docs – `FieldProps`
A function that takes the value from the form values and the name of the field and formats the value to give to...
Read more >
Update the value on input blur in react-final-form
I'm using react-number-format with react-final-form . My component looks like this: const CurrencyInput = props => { ...
Read more >
Jared Palmer on Twitter: "In the next minor release of Formik ...
In the next minor release of Formik, we will begin gently deprecating the OG formik.handleChange and formik.handleBlur. These will be available via formik....
Read more >
Formik 3 Alpha | Blog
But, before we get into the bad news, let's first share the good news: New parse , format , and formatOnBlur props! The...
Read more >
React Final Form - Format On Blur Example - CodeSandbox
Demonstrates how to use the formatOnBlur prop to postpone the formatting of a form field value until the field loses focus. react-final-form. final-form....
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