avalla
avalla

Reputation: 570

react-final-form state does not contains empty inputs

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 :)

Upvotes: 5

Views: 1993

Answers (1)

Erik R.
Erik R.

Reputation: 7272

Try this:

<Field
  name="myfield"
  component="input"
  type="text"
  allowNull                                      // <-------
  parse={value => (value === "" ? null : value)} // <-------
/>

Upvotes: 8

Related Questions