react-final-form icon indicating copy to clipboard operation
react-final-form copied to clipboard

Specify `parse={null}` behavior on the form level

Open ThiefMaster opened this issue 7 years ago • 5 comments

When creating a form to edit an existing object the empty-to-undefined conversion is problematic for optional fields that can be cleared by the user. Having to specify parse={null} in every field is rather annoying and not DRY - also, it's easy to forget.

It would be nice if there was an option to set this behavior on the <FinalForm> itself.

ThiefMaster avatar Nov 26 '18 15:11 ThiefMaster

Anyway it would be nice to have empty strings or null values in the values object. So you could do a patch or a spread to an existing object and it would overwrite the fields correctly.

phzimmermann avatar Nov 30 '18 13:11 phzimmermann

this is the most important feature missing in final-form.

I would create two options:

  1. First would provide empty value of the correct type empty text text fields-> '' empty multiselect -> [] empty checkbox -> false

  2. second option would be to use NULL for the currently undefined values empty text field: -> null empty multiselect -> null empty checkbox -> null

It is causing a lot of issues currently when working with graphql. parse={null} on the <Field is not a solution since if the field is untouched, it is not parsed (left undefined)

zsolt-dev avatar May 15 '19 17:05 zsolt-dev

Wow, this discovered this bug in my app. It's totally NOT expected that '' is converted to undefined by default.

flybayer avatar Jun 05 '19 14:06 flybayer

@zsolt-dev Hi there, did you figure out any way to parse untouched fields?

svetlanapuro avatar Mar 12 '20 15:03 svetlanapuro

Why does react-final-form add a default parse behaviour of converting empty string to undefined?

final-form itself doesn't do that, so I don't follow why the React wrapper is adding this extra parsing logic.

(Like @flybayer, this was totally unexpected, and has just led to a hard-to-find bug being raised in the app I'm working on.)

RoystonS avatar Oct 10 '23 08:10 RoystonS