Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify parse={null} behavior on the form level #384

Open
ThiefMaster opened this issue Nov 26, 2018 · 5 comments
Open

Specify parse={null} behavior on the form level #384

ThiefMaster opened this issue Nov 26, 2018 · 5 comments

Comments

@ThiefMaster
Copy link
Contributor

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.

@phzimmermann
Copy link

phzimmermann commented Nov 30, 2018

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.

@zsolt-dev
Copy link

zsolt-dev commented May 15, 2019

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)

@flybayer
Copy link

flybayer commented Jun 5, 2019

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

@iloveip
Copy link

iloveip commented Mar 12, 2020

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

@RoystonS
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants