React-admin: Form ignores empty string values

Created on 20 Aug 2019  路  12Comments  路  Source: marmelab/react-admin

What you were expecting:
Submitting a form with an empty string value submits that value along with the form.

What happened instead:
A TextInput value == "" is ignored altogether when submitting the form.

Steps to reproduce:
Create a SimpleForm with a TextInput field. Edit the field, and then delete all text (if you leave it empty, it _will_ submit a null value). Submit the form and observe the params that are sent in the request. The empty field is not present at all.

Related code:
Will try to get a sandbox posted shortly w/ code.

Environment

  • React-admin version: v3.0.0-alpha.2
  • Last version that did not exhibit the issue (if applicable): 2.9.5
  • React version: 16.9.0
  • Browser: Chrome Version 76.0.3809.100
bug

Most helpful comment

I agree, we should handle that at the form level if possible

All 12 comments

Most probably not an issue in react-admin.聽See https://github.com/final-form/react-final-form/issues/430

Thanks @djhi. Based on the thread here: https://github.com/final-form/react-final-form/issues/130, the only real solution within react-admin is to create a wrapper for TextInput like below and use that in place of react-admin's TextInput. It seems this would be closest to the previous behavior with redux-form. Do you think this would be a sensible default for TextInput in react-admin?

import React from 'react'
import { TextInput } from 'react-admin'

const identity = value => (value)

export default props => <TextInput parse={identity} {...props} />

If we want this behavior, I'd rather go with the form wide solution explained here in the same issue (including the next two comments).

@fzaninotto What do you think?

I agree, we should handle that at the form level if possible

Fixed by #3758

This does not seem to have fixed the simple TextInput? If I empty a text input, it gets removed from the output, and I don't get an empty string. That's what I expected would happen with this fix. The identify fix as suggested above works.

Did I miss something?

@berenddeboer I don't reproduce your bug on master. When I empty a text input, the app sends an update message to the dataProvider, with a null value for the field I emptied.

What's your react-admin version?

Not an empty string? Null values won't work for me as the field is required (but can be empty), but that's perhaps contradictory, I could change the schema to allow nulls. But I didn't see the field listed in the variables, but hadn't looked at the actual graphql fields it sends. Will look at that to double check.

My react-admin version is 3.1.2, I believe that was the latest until recently.

Have same issue on 3.5.5 version

Also seeing this seems to have regressed.

Upon checking, it appears that the data is being sent to my dataProvider... nothing has changed there, so very curious as to why this is now behaving differently.

Was able to fix on my end, so disregard.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alukito picture alukito  路  3Comments

ericwb picture ericwb  路  3Comments

kdabir picture kdabir  路  3Comments

samanmohamadi picture samanmohamadi  路  3Comments

kikill95 picture kikill95  路  3Comments