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.

Normalizing values differently from the store

See original GitHub issue

Reading the docs I see that normalizing has the following behaviour: Store and Field values are the same, i.e: if I type 333-333-3333 for the phone field, in the store I get:

form: {
    normalizing: {
      values: {
        min: 1,
        max: 10,
        phone: '333-333-3333'
      },
      ...
    }
} 

it would be great to know a way to store the value without the formatting. I know it would be easy to do this with just react, but, it would be useful when I have initial values in redux-form. Let’s say I get from database the phone number as: ‘3333333333’, then I put it in initialValues for the redux-form, it should be rendered correctly in the Field through normalize. The phone number is a simple case because I have some complex components that would benefit from the behavior I’ve described.

Maybe I did not find the right concept for doing it. But the thing is I’d like to take the values from the store and send them to the API “normalized” or “well-formatted”.

Could it be achieved with redux-form?

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
sbkncommented, Mar 21, 2017

The assumption is wrong, because all normalize does is modify the value before it gets stored. In this example user would type in only 3’s (without the dash), but store would receive the normalized value, thus “333-333-3333”. And this is also the value which the field displays to user, so though you’ve never typed in any dash, you’re still seeing the value including the dash.

What I think you want is:

  • User types in random input
  • Input is being modified by a normalize method
  • Normalized value is being stored
  • Value is being presented to the user in a formatted state (format)
1reaction
sbkncommented, Mar 22, 2017

shouldn’t format (function) be applied to the field only and not to the redux store?

No, there is no such thing as “only field”.

Consider the following:

  • Normalized value is in store (e.g. “33333”)
  • Field shall display value from store, thus stored value is being sent through the format function and formatted value is being put into field (e.g. “333-33”)
  • Field needs to save its current value in store, thus value from field is going through the normalize function and being saved to store afterwards (e.g. “33333”)

All in all - the field is trying to save its current value to store, so your normalize function needs to remove all formatting which is applied by format

Read more comments on GitHub >

github_iconTop Results From Across the Web

How, When, and Why Should You Normalize / Standardize ...
For machine learning, every dataset does not require normalization. It is required only when features have different ranges.
Read more >
When, Why, and How to Normalize Data - Plutora
In brief, data normalization entails structuring a database using normal forms. To phrase it another way, data normalization is all about ...
Read more >
3 Reasons to Normalize Your Data
Data normalization is the systematic process of grouping similar values into one common value, bringing greater context and accuracy to your marketing database....
Read more >
What Is Data Normalization? – BMC Software | Blogs
Data normalization is the organization of data to appear similar across all records and fields. It increases the cohesion of entry types leading ......
Read more >
Relational Database Normalization Process
By normalizing, we store data where it logically and uniquely belongs. The normalization process involves a few steps and each step is called...
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