Normalizing values differently from the store
See original GitHub issueReading 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:
- Created 7 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
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:
normalize
methodformat
)No, there is no such thing as “only field”.
Consider the following:
format
function and formatted value is being put into field (e.g. “333-33”)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 byformat