From my understanding, this is how an optional text-field would be handled in a backend
not present in the object => optional => don't touch it
empty string "" => set the value as an empty string
any other string => set the value.
So it might make sense to remove the value from the object when the state has not changed, but to make it null when it is empty feels a bit counter-intuitive to me. In pydantic for example this would be an error:
This seems to be a choice made by react-admin dev's and that*s okay, but I would like to get your motivation on this and maybe you can point me to the backends that implemented this in that particular way?
I will also send a pull-request to update the docs with an example if that's okay.
What you were expecting:
I have a couple of forms with textfields.
An example openapi spec would be:
Here is what i would expect:
create:
update
What happened instead:
When "nickname" was empty, in the request object "nickname" was set to null. this is documented behavior: https://github.com/marmelab/react-admin/blob/master/docs/SimpleForm.md#sanitizeemptyvalues and it is stated that this is expected by most backends. https://github.com/marmelab/react-admin/blob/032e1464cd23cf15dbc4d641e9663f74b37b9563/packages/ra-core/src/form/useInput.ts#L23-L24
From my understanding, this is how an optional text-field would be handled in a backend
So it might make sense to remove the value from the object when the state has not changed, but to make it null when it is empty feels a bit counter-intuitive to me. In pydantic for example this would be an error:
Also this reads to me as it would be preferable to use an empty string: https://stackoverflow.com/questions/45575493/what-does-required-in-openapi-really-mean
This seems to be a choice made by react-admin dev's and that*s okay, but I would like to get your motivation on this and maybe you can point me to the backends that implemented this in that particular way?
I will also send a pull-request to update the docs with an example if that's okay.
related issues/prs
https://github.com/marmelab/react-admin/pull/8188 https://github.com/marmelab/react-admin/pull/8262
https://github.com/marmelab/react-admin/issues/8472
Environment