Skip to content

Empty (null/undefined) properties are not submitted in SelectArrayInput, SelectInput, DateInput #10679

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

Open
yonitou opened this issue Apr 16, 2025 · 2 comments

Comments

@yonitou
Copy link

yonitou commented Apr 16, 2025

What you were expecting:
When I have a SimpleForm, every key/value couple that is present in the form must be present in the final object when submitting it

What happened instead:
For some kind of inputs : DateInput, SelectArrayInput, SelectInput, if the input has not been touched (is not dirty), the key is not present in the final object.
I tried to use parse, format, sanitizeEmptyValues, transformOptions, defaultValue, none of them worked. I don't know in which version the issue appeared but I know that it was working before.

Related code:

<SelectInput
	choices={[{id: 1, name: "test"}, {id: 2, name: "test2}]}
	label="resources.usages.fields.doseIsCheck"
	source="doseIsCheck"
/>

When using a simple SelectInput like this one, if I'm not "touching" the input, the key doseIsCheck won't be present when submitting the form. I didn't customize any parent component like Create or SimpleForm. It's really boiler plate code

Environment

  • React-admin version: 6.5.4
  • Last version that did not exhibit the issue (if applicable): Hard to say :/
  • React version: 18
  • Browser: Safari
@yonitou yonitou changed the title Empty (null/undefined) properties are not submitted Empty (null/undefined) properties are not submitted in SelectArrayInput, SelectInput, DateInput Apr 16, 2025
@djhi
Copy link
Collaborator

djhi commented Apr 23, 2025

Thanks for reporting this. Please provide a sample application showing the issue, preferably a sandbox forked from

@saloua-ch
Copy link

I tried to reproduce this issue in react-admin v5.6.4 but couldn't replicate the problem. Here's what I tested:

  1. Created a test form with all the mentioned input types:

    • SelectInput with default value
    • DateInput with default value
    • SelectArrayInput with default value
  2. Test setup:

const PostCreateTest = () => {
  const notify = useNotify();

  const onSubmit = (data) => {
    console.log('Form submission data:', data);
    notify('Form submitted with data: ' + JSON.stringify(data));
  };

  return (
    <Create>
      <SimpleForm onSubmit={onSubmit}>
        <TextInput source="title" required />
        <SelectInput
          source="category"
          choices={[
            { id: 'tech', name: 'Technology' },
            { id: 'lifestyle', name: 'Lifestyle' },
          ]}
          defaultValue="tech"
        />
        <DateInput
          source="publishedAt"
          defaultValue={new Date().toISOString().split('T')[0]}
        />
        <SelectArrayInput
          source="tags"
          choices={[
            { id: 'js', name: 'JavaScript' },
            { id: 'react', name: 'React' },
            { id: 'ts', name: 'TypeScript' },
          ]}
          defaultValue={['js']}
        />
      </SimpleForm>
    </Create>
  );
};
  1. Results:
  • When submitting the form without touching any inputs except the required title field
  • All default values are properly included in the submission data:
{
  "category": "tech",
  "publishedAt": "2025-04-25",
  "tags": ["js"],
  "title": "title"
}

This suggests the issue might be specific to v6.5.4. Could you provide:

  1. A minimal reproduction in v6.5.4 showing the missing values?
  2. The exact steps to reproduce in that version?

You can fork and modify this example: https://stackblitz.com/edit/github-vnan7rfb?file=src%2Fposts%2FPostCreate.tsx,src%2Fposts%2FPostCreateTest.tsx,src%2Fposts%2Findex.tsx

Image

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

No branches or pull requests

3 participants