Can my empty TextInput value be sent to the DataProvider as empty string instead of converted to null?

Viewed 1025

I'm using a <TextInput> in a <SimpleForm> and when I clear out the value at runtime, react-admin sets the property's value to null when it sends the values to the DataProvider. I would like to store empty strings instead of null. Is that possible? If so, how?

3 Answers

Current version of react-admin allows you to change this behavior with sanitizeEmptyValues prop:

export const PostEdit = (props) => (
    <Edit {...props}>
        <SimpleForm sanitizeEmptyValues={false}>
            <TextInput source="title" />
            <JsonInput source="body" />
        </SimpleForm>
    </Edit>
);

More details in official docs: https://marmelab.com/react-admin/CreateEdit.html#setting-empty-values-to-null

You can try to add initialValue="" prop into it, like

<TextInput initialValue="" />

Which will override it into an empty string when it is null or undefined

Related