react-final-form state does not contains empty inputs
Asked Answered
L

1

5

I would like to have empty/null properties inside the state when user is deleting the content from an input.

If you see on the example the state is empty when user is clearing the input. I use the state to update data on database, so when the code updates the old data with new one the value is not updated (there is no property!).

Example: https://codesandbox.io/s/3qvqnv6216

I cannot find any smart way to leave the property inside the state.

Thanks :)

Lucan answered 8/5, 2018 at 13:50 Comment(0)
P
8

Try this:

<Field
  name="myfield"
  component="input"
  type="text"
  allowNull                                      // <-------
  parse={value => (value === "" ? null : value)} // <-------
/>
Petrochemical answered 10/5, 2018 at 15:23 Comment(3)
thanks, it works, I cannot understand why there isn't an option for this :|Lucan
As the author of the library states here the reason can be found in the library's FAQ.Quesenberry
Great solution, took me almost one day of searching for a solution.Cadency

© 2022 - 2024 — McMap. All rights reserved.